Tag: java

Associated table Not getting updated

I’m new to h2 db. I’m populating (inserting) some data in Table A. So whenever I add some data in Table A ,How would I ensure that Table B should also get updated. Table A Prim_Key1 INDEX NAME 1 1 A 2 2 B 3 3 C Table B Prim_Key2 INDEX Value Prim_key2–> Populating form […]

Persistence Framework Making 'Batch' Calls, Need 'RPC' Call

I’m attempting to make an RPC database call using MyBatis persistence framework alongside using the JTDS jdbc driver. The problem is that they are being sent as batch calls to sqlserver. Here is an example of the mapper xml using a stored proc that takes 2 parameters: <select id=”doSomething” parameterType=”com.myCompany.Member” resultMap=”memberMap” statementType=”CALLABLE” > {call dbo.getAMember_sp […]

How to remove white space character when inserting data through prepared statement in Java

I am using SQL Server as the database and I want to insert data to a table through my Java application. It is successful but when I retrieve the data which has been just inserted I find there is some whitespace character behind the word. I debugged my program but everything looks fine, even until […]

Hibernate save function does update instead of insert using spring mvc

In my case, there are two tables. Both the tables are joined with Username. Username being the primary key in Login Table and Foreign Key in Customer Table. I want to insert data in those two tables using hibernate save function. When I first run the server and click on save button, it inserts the […]

Invalid Column Index

Below is part of my code. I keep getting errors for my database part. I’ve looked them up multiple places and can’t seem to find an answer. Any suggestions? The code and what’s printed as errors are shown below! public void deleteEmployee() { String sqlQuery; sqlQuery = “DELETE FROM JAVAUSER.EMPLOYEE”; System.out.println(sqlQuery); sendDBCommand(sqlQuery); } public void […]

Mocking a database for system testing

I’ve read the following posts: Is there a way to run MySQL in-memory for JUnit test cases? Stubbing / mocking a database in .Net SQL server stub for java They seem to address unit/component level testing (or have no answers), but I’m doing system testing of an application which has few test hooks. I have […]

Datasource Microsoft JDBC Driver for SQL Server (AlwaysOn Availability Groups)

I have a question related to the scenario when connecting from a Java application using the Microsoft JDBC Driver 4.0 to a SQL Server 2014 with AlwaysOn Availability Groups set up for high availability. With this set up, we will be connecting to an availability group listener (specified in the db connecting string instead of […]

Testing date values with HSQLDB

We use SQLServer in production, but HSQLDB for our integration tests. HSQLDB is used because it’s an in-memory database. I have an SQLServer SQL that executes the following code: select convert(varchar(8), pos_val_date, 112) from wscpos; In HSQLDB, this does not work. The code should be: select to_char( pos_val_date, ‘YYYYMMDD’) from wscpos; What’s the best practice […]

spark dataframe sqlserver

I’m trying to insert records to SQL Server Database using DataFrameWriter using the below in the insert statement: List<MyDataModel> dataRecords = MyProcess.getData(input); JavaRDD <MyDataModel> dataRecordsRDD = jsc.parallelize(dataRecords); DataFrame schemaDataRecords = sqlContext.createDataFrame(dataRecordsRDD, MyDataModel.class); schemaDataRecords.write().mode(“append”).options(options).jdbc(url, myTable, jdbcConnProperties); Getting the exception table exists while trying to insert records: com.microsoft.sqlserver.jdbc.SQLServerException: There is already an object named ‘MY_TABLE’ in the […]

Binary Data Type in H2, Sql-Server, MySql

I need to store a serialized Object as binary data in a H2 table (also in MySql, SqlServer, Hsqldb, etc, as the app have options to select the database). This object only weights few bytes, it is just a POJO with some Strings, Integers and Boolean values, nothing extraordinary. I create the VARBINARY(1000) column set […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.