3

I have:

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

However this results in the following exception:

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...

Stephane Grenier
  • 15,527
  • 38
  • 117
  • 192

1 Answers1

2

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

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

Stephane Grenier
  • 15,527
  • 38
  • 117
  • 192
wwadge
  • 3,506
  • 1
  • 19
  • 28
  • One issue remains with this, the problem is that the call doesn't actually shutdown the database like it does if you do a straight DriverManager.getConnection(...). So whatever BoneCP is doing, it's not letting the Derby Thread end like it normally would... – Stephane Grenier Nov 12 '12 at 07:46