Will, I also found getting Datasources in a servlet init method yields new
connections for each getConnection().  However, If I casted the Datasource
to a ConnectionPoolDataSource, pooling works.

Try getting a ConnectionPoolDataSource in the init method.  Something like:

public void init( ServletConfig config ){

            Context ic = new InitialContext();
            cpds = (ConnectionPoolDataSource)ic.lookup(dbName);
}

then use the cpds to get a PooledConnection, and finally a Connection from
that.

doGet {
     PooledConnection pc = cpds.getPooledConnection();
     conn = pc.getConnection();
}

Still, I'm not sure why just using a Datasource doesn't use pooling.  I
believe it should & that the application layer should not be getting
ConnectionPoolDataSources & PooledConnections.

-Craig



                                                                                       
             
                    Will Stranathan                                                    
             
                    <will@thestrana       To:     [EMAIL PROTECTED]        
             
                    thans.com>            cc:     (bcc: Craig Reichenbach/CAM/Lotus)   
             
                                          Subject:     Re: Tyrex Pools                 
             
                    10/01/2001                                                         
             
                    11:42 PM                                                           
             
                    Please respond                                                     
             
                    to tomcat-dev                                                      
             
                                                                                       
             
                                                                                       
             




Ah - that makes sense.  However, it seems to still be doing the same
thing.  I just threw together a simple JSP to test it, and put the ds
lookup in jspInit().  The lookup is only getting executed once, but it
still looks like no connections are getting re-used.

Anything else for me to look at?

Will Stranathan

<%!
     DataSource ds = null;
     public void jspInit() {
         try {
             Context ctx = new InitialContext();
             ds = (DataSource)ctx.lookup("java:comp/env/jdbc/Directory");
             System.out.println("did lookup");
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
%>


<%
     Connection conn = null;
     if (ds != null) {
         try {
             conn = ds.getConnection();

etc....



Remy Maucherat wrote:

> Instead, I would retrieve the DataSource in the init() method of the
> servlet, and put it in an instance variable.
>
> Remy
>
>






Reply via email to