commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Austin Mills" <>
Subject DBCP question about throwing an exception when double-closing a connection
Date Sun, 05 Sep 2004 05:18:08 GMT
Hello all,

I just started using DBCP and am pretty happy with it, but I've come across something that
seems a bit strange to me. When a
connection received from the DBCP pool has close() called upon it two times, on the second
call, it will throw an SQL exception such

java.sql.SQLException: Connection is closed.
        at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.checkOpen(
        at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(
        at... (my code from here on)

After browsing the docs/web site, this seems to be intended as a feature -- and I can understand
that, as it's generally indicative
of poor logic to close a connection twice. This is, however, directly in contradiction of
the interface java.sql.Connection, which
states in the javadocs of the close() method:

"Calling the method close on a Connection object that is already closed is a no-op."

Functionally, what this means is that when a developer has an existing codebase where connections
are double-closed (which is legal
within the interface definition), he can switch to the DBCP pooling system from another system
and end up having exceptions thrown
from double-closing Connections (as I did).  

I had browsed through the mailing list archives to see if there had been any discussion on
this point, but I was unable to find any.
My question is, is this a conscious decision on the part of the developers to break away from
that point in the interface
definition? Or is it just something that was overlooked in the interests of writing better

Let me know if this should be moved to the developers list instead.

Austin Mills
SensorLogic | M2M made easy.
972-934-7375 x2107
972-934-7376 (fax)

Join SensorLogic at Wireless Sensing Solutions 2004 and receive a 25% discount on the conference
program when you register online at with SensorLogic priority code:  B0104. 

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message