tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tim Lucia" <>
Subject RE: tomcat + postgres
Date Thu, 02 Feb 2006 12:02:40 GMT
Close() on a pooled connection is almost certainly releasing it, rather then
actually closing it (it would depend on the pooling implementation.)
org.apache.commons.dbcp.PoolableConnection, for example, has a
"reallyClose()" method which closes the underlying connection.  

The <resource...> probably registers an object with JNDI that implements
javax.sql.ConnnectionPoolDataSource.  I.e., you don't need to ever use that
interface directly.  It's not part of J2EE 1.4 (it was last scene in 1.3).


-----Original Message-----
From: Matthew Whisenhunt [] 
Sent: Thursday, February 02, 2006 6:06 AM
To: Tomcat Users List
Subject: Re: tomcat + postgres

Thanks Tim, I have yet to post an intelligent question.
You answered my real question though.
Just for good measure I'll mention the book was O'Reilly's Java 
Enterprise Best Practices... ah and the _interface_ was 
javax.sql.ConnnectionPoolDataSource . Yeah, weird in the example they 
actually instantiate an object that type....

So when I :
        DataSource ds = null;
        try {
            InitialContext cxt = new InitialContext();
            ds = (DataSource) cxt.lookup( "java:/comp/env/jdbc/postgres" );
        } catch (Exception e) {e.printStackTrace(out);}

        if(ds != null)try{
            Connection conn = ds.getConnection();
            PreparedStatement stmt = conn.prepareStatement("SELECT name 
FROM tonight");
            ResultSet rs = stmt.executeQuery();

conn.close() I am actually just releasing the connection and not really 
closing it?


Tim Lucia wrote:
> Without knowing what book you refer to, and what class or interface 
> ConnectionPoolDataSource represents, it is difficult to know for sure.
> DataSource (javax.sql.DataSource) is an Interface, not a class.  
> Objects returned from tomcat are sure to implement this interface, and 
> are pooled behind the scene, i.e., you do not care what the 
> implementation class is. So, I would recommend going with 
> javax.sql.DataSource.
> I.e., in context.xml, you say:
> <Resource name="my/datasource/name" type="javax.sql.DataSource"
> ...
> </Resource>
> And in your code, you expect the returned object to be a 
> javax.sql.DataSource (from the initial context, lookup, etc.)
> Tim
> -----Original Message-----
> From: Matthew Whisenhunt []
> Sent: Wednesday, February 01, 2006 4:06 PM
> To:
> Subject: tomcat + postgres
> I followed the howto about connection pooling at
> and I had following question:
> Do I use the DataSource class like in the example or the
> ConnectionPoolDataSource class (like it says to do in my book)?
> Any insights would be very appreciated.
> -Matt
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

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

View raw message