gpt4 book ai didi

java - HSQLDB prepareStatement ("SET SCHEMA ?") 错误

转载 作者:行者123 更新时间:2023-12-01 15:59:03 29 4
gpt4 key购买 nike

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

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()");
}

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

这是完整的堆栈跟踪:
javax.batch.operations.JobStartException: com.ibm.jbatch.container.exception.PersistenceException: java.sql.SQLException: java.lang.NullPointerException java.lang.NullPointerException

at com.ibm.jbatch.container.api.impl.JobOperatorImpl.start(JobOperatorImpl.java:92)
at factory.jf.privacy.service.loggedareasfilter.batch.AzzaTest.testBatchChunkException(AzzaTest.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: com.ibm.jbatch.container.exception.PersistenceException: java.sql.SQLException: java.lang.NullPointerException java.lang.NullPointerException
at com.ibm.jbatch.container.services.impl.JDBCPersistenceManagerImpl.createJobInstance(JDBCPersistenceManagerImpl.java:1682)
at com.ibm.jbatch.container.jobinstance.JobExecutionHelper.getNewJobInstance(JobExecutionHelper.java:89)
at com.ibm.jbatch.container.jobinstance.JobExecutionHelper.startJob(JobExecutionHelper.java:120)
at com.ibm.jbatch.container.impl.BatchKernelImpl.startJob(BatchKernelImpl.java:124)
at com.ibm.jbatch.container.api.impl.JobOperatorImpl.startInternal(JobOperatorImpl.java:123)
at com.ibm.jbatch.container.api.impl.JobOperatorImpl.start(JobOperatorImpl.java:88)
... 28 more
Caused by: java.sql.SQLException: java.lang.NullPointerException java.lang.NullPointerException
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)
at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:281)
at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:281)
at com.ibm.jbatch.container.services.impl.JDBCPersistenceManagerImpl.setSchemaOnConnection(JDBCPersistenceManagerImpl.java:396)
at com.ibm.jbatch.container.services.impl.JDBCPersistenceManagerImpl.getConnection(JDBCPersistenceManagerImpl.java:334)
at com.ibm.jbatch.container.services.impl.JDBCPersistenceManagerImpl.createJobInstance(JDBCPersistenceManagerImpl.java:1670)
... 33 more

最佳答案

这个准备好的语句的编译结果是 NullPointerExcepion数据库数据库 :

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();

关于java - HSQLDB prepareStatement ("SET SCHEMA ?") 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38323225/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com