[jboss-user] [JCA/JBoss] - Error while closing connection from a pool

rohit.macherla do-not-reply at jboss.com
Wed Jan 21 04:23:25 EST 2009

I am using JBoss 4.2.2.GA on a HP Unix platform. For the sake of delegating connection management to the application server, I have started using connection pooling. 
The code I used was : 

  | InitialContext jndiCntx = new InitialContext();
  | DataSource ds = (DataSource) jndiCntx.lookup("java:/testapi");
  | Connection con = (Connection)ds.getConnection();

But with this, I was unable to invoke any Oracle Stored Procedures that takes in an Oracle Object. I have resolved this issue by fetching the connection as : 

  | InitialContext jndiCntx = new InitialContext();
  | WrapperDataSource ds = (WrapperDataSource) jndiCntx.lookup
  | ("java:/clarityapi");
  | org.jboss.resource.adapter.jdbc.WrappedConnection wrappedCon = (WrappedConnection) ds.getConnection(
  | );
  | java.sql.Connection connection = wrappedCon.getUnderlyingConnection();

Using this, I am able to send in any Oracle Objects by using StructDescriptor's and ArrayDescriptor's wherever necessary. Also, necessary validations were put in to check if the 'wrappedCon' is 'closed' and if so I was retrying for a maximum of 4 times to check for stale connections. 
However, the problem comes in when I am trying to close the connection. If i close it using : 
there is no problem. But in the next invocations of the : 
I receive the following statements: 

anonymous wrote : 
  | [CachedConnectionManager] Closing a connection for you. Please close them yourself: org.jboss.resource.ada 
  | pter.jdbc.WrappedConnection at 1c1ec0e 

and the subsequent connections i receive the following error :
anonymous wrote : 
  | java.sql.SQLException: Closed Connection
  |         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:187)
  |         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:229)
  |         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:292)
With the debug statements, I have found the following status for the subsequent calls: 
wrappedCon.isClosed : false 
wrappedCon.getUnderlyingConnection.isClosed() : true . 
So, the WrappedConnection object is not closed, but the underlying java.sql.Connection is closed. 
This "Closing a connection for you..." may be only a debug statement given for my benefit but even if I disable it, the fact is that the connection is getting closed when I wanted it to be just put back into the connection pool. 

The same scenario exists when I do : 
wrappedCon.close(); instead of connection.close(); 

Please suggest me a valid way to close these wrapped connections. I was under the impression that these close() methods would place it back into the connection pool, but probably with this output I think the JBoss connection pooling needs to be handled differently in my code. 

Thanks in advance.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4203529#4203529

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4203529

More information about the jboss-user mailing list