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:
[CachedConnectionManager] Closing a connection for you. Please close them yourself: org.jboss.resource.ada
and the subsequent connections i receive the following error :
java.sql.SQLException: Closed Connection
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.