True ... old habits die hard :-)

Craig


On Thu, 10 Feb 2005 20:25:57 +0100, Bernard D'Have <[EMAIL PROTECTED]> wrote:
> I think the first conn.close is unneeded, because the finally block is
> always executed.
> 
> Bernard
> 
> -----Original Message-----
> From: Craig McClanahan [mailto:[EMAIL PROTECTED]
> 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 {
>                 conn.close();
>             } 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.
> 
> Craig
> 
> On Thu, 10 Feb 2005 10:14:17 -0800, Paul Hsu <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to