ello,
 
As many people mentioned, there is a lot of confusion about databse connection pooling in tomcat 4. I spent some time trying all sorts of combinations (tyrex, dbcp, etc.) to get connection pooling working because there is little documentation on this topic and the products it uses. I got it working using tomcat's default library (tyrex) and here is what I found:
1. in web.xml, do this:
    <resource-ref>
      <res-ref-name>jdbc/MyDB</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
    </resource-ref>
 
2. in server.xml do this (I am using Sybase with jconn2.jar, which comes with SybConnectionPoolDataSource):
 
          <Resource name="jdbc/MyDB" auth="Container"
                    type="javax.sql.DataSource"/>
                   
          <ResourceParams name="jdbc/MyDB">
            <parameter>
             <name>driverClassName</name>
               <value>com.sybase.jdbc2.jdbc.SybConnectionPoolDataSource</value>
            </parameter>
           <parameter>
                <name>driverName</name>
               <value>jdbc:sybase:Tds:romen:1234</value>
            </parameter>
            <parameter><name>user</name><value>foo</value></parameter>
            <parameter><name>password</name><value>bar</value></parameter>
          </ResourceParams>
 
3. in my java code, do this:
            Context ctx=new InitialContext();
            Context envCtx=(Context)ctx.lookup("java:comp/env");
            ConnectionPoolDataSource pds=(ConnectionPoolDataSource)envCtx.lookup("jdbc/MyDB");
            connection = pds.getPooledConnection().getConnection();
4. the above works with jdk1.4 using tomcat 4.0.3 (note that the tomcat lite binary distribution is missing tyrex*.jar, so if you used that, you need to manually put the jar in tomcat's common/lib)
 
5. to get the above to work under jdk131_* using tomcat 4.0.3, I had to put jta.jar in tomcat's common/lib, because it was complaining about javax.transaction... class missing.
 
6. note that there is no way to specify the connection pool size, etc. In tomcat 4.1's documentation (JNDI-HOW-TO) it mentions parameters like maxIdle, maxActive, etc. Therefore, I believe these are not supported in tomcat 4.0.* but is in tomcat 4.1's product development plan.
 
7. and this setting really pools the connection. I checked this using netstat and saw that there was one or two connections established, as opposed to dozens of them (when I used SybDataSource in server.xml and DataSource in java code) when I madly clicked the links on my web page (each link does a db query). The only thing is, the connection's life time seems very short (a few seconds idle) and I could not control the pool size, etc. as mentioned in above point.
 
Hope I have helped.
 
cheers
romen
 
 
 
--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>


Reply via email to