骨CP& Derby-如何正确关闭 [英] BoneCP & Derby - How to properly shutdown

查看:166
本文介绍了骨CP& Derby-如何正确关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有:

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)

如何避免出现此异常.我已经尽我所能尝试了所有可能的方式...

How can I avoid this exception. I've tried every possible way I can think of...

推荐答案

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

Unless you are running v0.8.1-beta2 or greater, set "disableConnectionTracking" to true in your config.

请注意,成功关闭后,您还应该期待Derby产生SQLException:

Please note that you should also expect an SQLException from Derby after a SUCCESSFUL shutdown: http://db.apache.org/derby/docs/dev/devguide/tdevdvlp40464.html

这篇关于骨CP& Derby-如何正确关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆