commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dirk Verbeeck <>
Subject Re: DBCP: Question about throwing an exception when Connection.close() is called twice
Date Sun, 19 Sep 2004 18:37:56 GMT
Hi Austin,

We know about the double close and the javadoc allows it but it also 
allows SQLExceptions to be thrown.

Personally I think the current behavior is useful because it helps 
detect the poor logic to close a connection twice.
This has been the behavior since 1.0.

-- Dirk

Austin Mills wrote:

> 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
> as:
> 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/archives, this seems to be intended as a feature (or at a fix
to a previous bug,
> ) 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 (bad, yes, but
> 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). 
> 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
> My hunch is that I should write this up as a bug in Bugzilla, but I wanted to get the
opinions of the developers.
> Thanks,
> Austin Mills
> Development
> 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