commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bernard D'Have" <>
Subject RE: DBCP
Date Thu, 10 Feb 2005 19:25:57 GMT
I think the first conn.close is unneeded, because the finally block is
always executed.


-----Original Message-----
From: Craig McClanahan [] 
Sent: Thursday, February 10, 2005 7:24 PM
To: Jakarta Commons Developers List
Subject: Re: DBCP

Calling BasicDataSource.close() will only close the connections still in the
pool -- not the ones that have been checked out.  It is designed to be
called only when your app is ready to shut down.

For normal usage, the best approach is something like this:

    DataSource ds = ... get your data source reference;
    Connection conn = null;
    try {
        conn = ds.getConnection();
        ... use the connection as needed ...
        conn.close(); // Returns this connection to the pool
    } catch (SQLException e) {
        ... deal with any exception ...
    } finally {
        if (conn != null) {
            try {
            } catch (SQLException e) {

That way, you're always returning the connection to the pool, even if an
exception occurs while you're using it.

BTW, your MySQL admin will show active connections for all the entries in
the pool, as well as those that have been checked out and are in use.


On Thu, 10 Feb 2005 10:14:17 -0800, Paul Hsu <> wrote:
> Hi,
> I have one question about DBCP. I like to know if any one have used 
> BasicDataSource.close(). In my program I set up a BasicDataSource and 
> get connection from MYSQL, I call BasicDataSource.close() right after 
> get connection, I still see the connectioin from MYSQL admin. I just 
> wonder this function is working?
> thanks,
> Paul

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

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

View raw message