WASdev / standards.jsr352.jbatch

Home of 'jbatch', a compatible implementation of the Jakarta Batch specification (and the former Reference Implementation for the JSR 352, Batch Applications for the Java Platform specification).
Other
21 stars 18 forks source link

Set SCHEMA is not valid SQL in Microsoft SQL Server #56

Closed FengLiqiong closed 6 years ago

FengLiqiong commented 6 years ago

The code below from JDBCPersistenceManagerImpl throws the exception below on Microsoft SQL Server:

exception:

com.ibm.jbatch.container.exception.PersistenceException:
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntaxnear the keyword 'SCHEMA'.
...
at
com.ibm.jbatch.container.services.impl.JDBCPersistenceManagerImpl.setSchemaOnConnection(JDBCPersistenceManagerImpl.java:398)

JDBCPersistenceManagerImpl:

String dbProductName = connection.getMetaData().getDatabaseProductName();
if (!"Oracle".equals(dbProductName)) {
PreparedStatement ps = null;
if ("MySQL".equals(dbProductName)) {
ps = connection.prepareStatement("USE " + schema);
} else {
ps = connection.prepareStatement("SET SCHEMA ?");
ps.setString(1, schema);
}
ps.executeUpdate();
ps.close();
}

In Microsoft SQL Server we can only grant users access to a schema and there is no SQL like "SET SCHEMA".

scottkurz commented 6 years ago

Fixed by commit c55cc5ee9676f8da0ba2b2646aa78cabf7e3279f