Tag: java

JDBC How to get all generated keys from single insert with many values query?

I’m inserting multiple rows using a PreparedStatement with a single query: String query = “insert into MyTable (a,b,c) values (?,?,?),(?,?,?),(?,?,?),(?,?,?)”; // insert 4 rows in a single query PreparedStatement stmt = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS); // .. here: loop to set all 4 x 3 values in my prepared statement And I want to get the IDs […]

Incorrect syntax near the keyword 'table' and could not extract ResultSet

I have created a project with SQL Server which the files: UserDAO.java* public class UserDAO { private static SessionFactory sessionFactory; static { sessionFactory = HibernateUtility.getSessionFactory(); } @SuppressWarnings(“unchecked”) public static List<User> findAll() { Session session = sessionFactory.openSession(); Criteria crit = session.createCriteria(User.class); List<User> userList = crit.list(); return userList; } } UserService.java public class UserService { public static […]

Is there a best practice for showing database changes on a JSP

We need to show database changes on a JSP page. The Information in the Database is changed by a legacy System, so I don’t have any change to get an event on Data change. So the problem is to keep the Database Information and the JSP Page in sync. Our first approach is to poll […]

SQL Server Nvarchar and Java prepared statement

I have a question regarding inserting strings to SQL Server 2008 R2. When I try to insert strings with some national letters, I receive “?” instead. I know that adding N at the beginning of a string literal will fix this problem, but I’m using JDBC prepared statements, like this: INSERT INTO MyTable(col1, col2) VALUES […]

PreparedStatement – how specify to use default value of column

I have a table created like this: CREATE TABLE [dbo].[LogInfo]( [date_current] [datetime] NULL, [classname] [varchar](500) NULL, [output] [varchar](500) NULL ) ON [PRIMARY] GO ALTER TABLE [dbo].[LogInfo] ADD DEFAULT (getdate()) FOR [date_current] GO so the ‘date_current’ column defaults to the current date and time. I have a prepared statement like this: PreparedStatement psInsert_ = conn.prepareStatement(“INSERT INTO […]

OpenJPA 1 – sequence table not being created

I have an entity class with the following annotation on its primary key: @GeneratedValue(strategy = GenerationType.AUTO). However, when I try to persist an instance of this class, I get com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name ‘OPENJPA_SEQUENCE_TABLE’. at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197) The table it’s looking for definitely does not exist in the database. The user it’s connecting to the database […]

What are the best practices for migrating an Oracle 10g database to Microsoft SQL 2008 R2? Application is using Hibernate

Basically what the title says. Going forward, we need to start supporting both database platforms (and will start writing migrations accordingly), but we need to do the first initial “port”. Our DBAs are confident they can convert the schema, tables, data types, etc. but our developers have less confidence that the DAOs will “just work”. […]

Connecting Android to SQL Server using JDBC

I am currently making an application for Android that is supposed to synchronize it’s data to MSSQL Server 2008. I am currently testing out ways to make it work, since I have never done it before. I should mention that the device will sync whenever it is connected to the USB port and not through […]

Java/MSSQL: java.sql.SQLException Invalid object name 'TableName'

I’m trying to move a java application from an old server to a new server. The application runs on Tomcat, uses Microsoft SQL Server as the backend DB, and used a system DSN defined in Data Sources (ODBC) to decide where to connect to. The old server used Windows 2000/SQL server 2000, the new server […]

Liquibase – checksum differs with different database vendors

I have a problem with Liquibase checksum when I try to run it on MSSQL and MySQL. In my MSSQL-base I have a changelog-entry with this checksum: 3:cf2f5de7a1dcc738bbc185e25fbcf6c9 When I run my liquibase against this database, it works just fine. Then, I copy the changelog-entry to my MySQL-database and try to run, and get this […]

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