commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anjan" <an...@bluewireless.com>
Subject [DBCP] : DelegatingConnection
Date Mon, 01 Apr 2002 21:08:16 GMT
Hi All,

	I have been using DBCP with mySQL and Oracle using
DriverManagerConnectionFactory, StackObjectPool and KeyedObjectPoolFactory.
I use the code like follows :
I am getting an exception when I call a sequence like this

====================
conn.close();
..
..
if (conn.isClosed()) {
   conn.close(); // THROWS THE EXCEPTION BELOW
}

Pls. see the actual context I'm getting problem down below.

I found that the method DelegatingConnection.isClosed() is delegating it to
the underlying driver (which is mySQL's isClosed()) where connection state
is open since the Connection was only returned to the pool.

Should we be intercepting the isClosed() at PoolableConnection() instead of
letting DelegatingConnection handle it ?

I'm currently eating the exception -- but believe that this should be fixed.
Can work on a fix if I get a suitable suggestion.

Thanks very much,
ANJAN. B


============EXCEPTION TRACE =====================
java.sql.SQLException: Connection is closed.
        at
org.apache.commons.dbcp.DelegatingConnection.checkOpen(DelegatingConn
ection.java:161)
        at
org.apache.commons.dbcp.DelegatingConnection.getAutoCommit(Delegating
Connection.java:136)
        at
org.apache.commons.dbcp.PoolableConnectionFactory.passivateObject(Poo
lableConnectionFactory.java:239)
        at
org.apache.commons.pool.impl.StackObjectPool.returnObject(StackObject
Pool.java:180)
        at
org.apache.commons.dbcp.PoolableConnection.close(PoolableConnection.j
ava:95)
        at
com.bluewireless.common.services.JakartaDbcpMgr.closeConnection(Jakar
taDbcpMgr.java:463)
=================================

==============THE ACTUAL CONTEXT WHERE EXCEPTION IS GENERATED
===================
func() {
    // Get Connection to each database and execute some work
    try {
        for (i = 0; i < NUM_POOLS; ++i) {
            DriverManager.getConnection(driverURL);
            // Use the connection to get resultSet, etc
            .
            // Close connection acquired just now
            closeConnection();
        } // end for
    } // end try
    catch () {
        ..
    } // end catch
    // do something else
    finally {
        closeConnection();
    } // end finally
} // end func

// closeConnection
void closeConnection(Connection conn) {
   if (!conn.isClosed())
      conn.close();
}
=================================


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message