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()*;
       }

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

Thanks,
Matt


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 [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 01, 2006 4:06 PM
To: users@tomcat.apache.org
Subject: tomcat + postgres


I followed the howto about connection pooling at http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html

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: [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