HSQLDB prepareStatement(“SET SCHEMA?”)错误

时间:2016-07-12 08:06:44

标签: java java-ee nullpointerexception hsqldb jbatch

我正在编写一个需要与HSQLDB连接的Jbatch服务,但在某个时刻它会抛出一个NullPointerException(和一些SQLExceptions / PersistenceExceptions)。调试我发现在类JDBCPersistenceManagerImpl.java中它将SCHEMA设置为?,但它似乎在HSQLDB中不受支持。

awk

有关如何修复它的任何想法?我已经尝试过另一个数据库(H2 db),但问题是一样的。

这是完整的堆栈跟踪:

private void setSchemaOnConnection(Connection connection) throws SQLException {
        logger.finest("Entering " + CLASSNAME +".setSchemaOnConnection()");

        if (!"Oracle".equals(connection.getMetaData().getDatabaseProductName())) {
            PreparedStatement ps = null;
            ps = connection.prepareStatement("SET SCHEMA ?");  -->ps = NullPointerException 
            ps.setString(1, schema);
            ps.executeUpdate(); 
            ps.close();
        }

        logger.finest("Exiting " + CLASSNAME +".setSchemaOnConnection()");
    }

1 个答案:

答案 0 :(得分:0)

编写此预准备语句会产生NullPointerExcepion hsqldb

Caused by: org.hsqldb.HsqlException: java.lang.NullPointerException
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.result.Result.newErrorResult(Unknown Source)
    at org.hsqldb.Session.execute(Unknown Source)
    ... 41 more
Caused by: java.lang.NullPointerException
    at org.hsqldb.ParserCommand.compileSet(Unknown Source)
    at org.hsqldb.ParserCommand.compilePart(Unknown Source)
    at org.hsqldb.ParserCommand.compileStatement(Unknown Source)
    at org.hsqldb.Session.compileStatement(Unknown Source)
    at org.hsqldb.StatementManager.compile(Unknown Source)
    ... 42 more

但是,当您将其更改为没有占位符的语句时,它可以工作:

ps = connection.prepareStatement("SET SCHEMA "+schema);
ps.execute();