1 Reply Latest reply on Mar 4, 2007 8:36 PM by Weston M. Price

    CachedConnectionManager is closing connection for me - why?

    ?ukasz Budnik Newbie

      Hi all,

      I have sucessfully deployed data source for DB2.
      I have also created DB2ConnectionFactory class:

      public final class DB2ConnectionFactory {
       private static Connection connection;
       static {
       try {
       connection = CachingServiceLocator.getInstance().getDataSource("java:/DataWeaverDS").getConnection();
       } catch (Exception e) {
       public static Connection getConnection() {
       return connection;

      well - it works i can connect to DB2 from my servlet but
      after the response is sent to browser i recieve this message:

      17:57:22,265 INFO [CachedConnectionManager] Closing a connection for you. Please close them yourself: org.jboss.resource.adapter.jdbc.WrappedConnection@50a11a
      java.lang.Throwable: STACKTRACE
       at org.jboss.resource.connectionmanager.CachedConnectionManager.registerConnection(CachedConnectionManager.java:290)
       at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:417)
       at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:842)

      next WWW request fails because of already closed connection:

      18:14:41,312 ERROR [STDERR] java.sql.SQLException: Connection handle has been closed and is unusable
      18:14:41,312 ERROR [STDERR] at org.jboss.resource.adapter.jdbc.WrappedConnection.checkStatus(WrappedConnection.java:537)
      18:14:41,312 ERROR [STDERR] at org.jboss.resource.adapter.jdbc.WrappedConnection.checkTransaction(WrappedConnection.java:524)

      my DS looks like this:

      <?xml version="1.0" encoding="UTF-8"?>

      is my data source definition missing something or is it my Java code?

        • 1. Re: CachedConnectionManager is closing connection for me - w
          Weston M. Price Master

          You should not attempt to cache connections. The typical usage pattern is
          acquire the connection, use the connection, close the connection. JBossJCA

          1) Acquire the connection
          2) Use the connection
          3) Close the connection

          JBossJCA is telling you two thing with the errror message

          1) You are not correctly closing your JDBC connections as a result, JBossJCA is having to close them for you.

          2)You are attempting to reuse a connection handle that has already been closed (by JBossJCA).

          Review your code and make sure it conforms to the above pattern. Note, there is nothing wrong with caching a DataSource as this is just a simple connection factory. However, the connection should be released (closed) after use.