gpt4 book ai didi

java - BoneCP & Derby - 如何正确关闭

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:31:31 24 4
gpt4 key购买 nike

我有:

BoneCP CONNECTION_POOL = ...;
CONNECTION_POOL.getConfig().setJdbcUrl("jdbc:derby:database...;shutdown=true");
Connection connection = CONNECTION_POOL.getConnection();
connection.close();
CONNECTION_POOL.shutdown();

但是这会导致以下异常:

3274 [com.google.common.base.internal.Finalizer] ERROR com.jolbox.bonecp.ConnectionPartition - Error while closing off internal db connection
java.sql.SQLException: Cannot close a connection while a transaction is still active.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.checkForTransactionInProgress(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.close(Unknown Source)
at com.jolbox.bonecp.ConnectionPartition$1.finalizeReferent(ConnectionPartition.java:187)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.base.internal.Finalizer.cleanUp(Finalizer.java:154)
at com.google.common.base.internal.Finalizer.run(Finalizer.java:127)

我怎样才能避免这个异常。我已经尝试了所有我能想到的方法...

最佳答案

除非您运行的是 v0.8.1-beta2 或更高版本,否则请在您的配置中将“disableConnectionTracking”设置为 true。

请注意,在成功关闭后,您还应该期望 Derby 抛出 SQLException:http://db.apache.org/derby/docs/dev/devguide/tdevdvlp40464.html

关于java - BoneCP & Derby - 如何正确关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13304891/

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