**************** original message
> From: Daryn Nakhuda <[EMAIL PROTECTED]>
> Date: Mon, 15 Apr 2002 11:43:57 -0700 (PDT)
> To: [EMAIL PROTECTED]
> Subject: Mysql pooling datasource in tomcat 4
> 
> 
> Has any one had success creating a pooling datasource for mysql in tomcat
> 4? 
> 
> I was able to successfully create a functional datasource jdni resource
> based on the instructions in the jndi resources HOW-TO

Unfortunately by using the Tomcat (4.0.x) default JNDI datasource factory
(aka Tyrex) you not only do not have a pool manager interface but you don't
have a pool.  The Tyrex factory only sets up one physical connection and one
pool instance AFAIK.

In order to create a pool you either can use the jakarta-commons DBCP
factory or write your own implementation.  Craig McClanahan recently posted
this DBCP implementation which works with TC 4.0.x.

**************** Craig's post
> It should be possible to use the DBCP based pool even with Tomcat 4.0.x by
> overriding the default JNDI factory for javax.sql.DataSource objects (I
> haven't tested this, but in theory it should all work).
> This requires the following steps:
> 
> * Download recent nightly builds of the Collections, Pool, and DBCP
> packages from Jakarta Commons
> (http://jakarta.apache.org/builds/jakarta-commons/nightly/) and put
> the JAR files into $CATALINA_HOME/common/lib along with your JDBC
> driver.
> 
> * Configure the "factory" parameter in the <ResourceParams> element
> to set the JNDI ObjectFactory class for this resource:
> 
>   <ResourceParams name="jdbc/EmployeeDB">
>     <parameter>
>       <name>factory</name>
>       <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
>     </parameter>
>     ... other configuration parameters ...
>   </ResourceParams>
> 
> * Configure the other parameter values of the <ResourceParams> element
> from the list of supported properties below:
> - driverClassName - Fully qualified Java class name of the JDBC driver
> - maxActive       - Maximum number of active connections at one time
> - maxIdle         - Maximum number of idle connections at one time
>                     (if more are returned to the pool, they will be
>                     closed to release database resources)
> - maxWait         - Number of milliseconds the pool will wait when there
>                     are no available connections before causing
>                     getConnection() to throw an exception
> - password        - Database password
> - url             - Connection URL (also accepts "driverName" for
>                     backwards compatibility)
> - user            - Database username
> - validationQuery - Optional SQL SELECT statement used to validate a
>                     connection before returning it to the application
>                     (must return at least one row).  This is helpful
>                     in catching stale connections because of timeouts
>                     or recycling of the database without stopping
>                     Tomcat.
> 
> Alternatively, you can use any other connection pool you like, if you
> create your own javax.naming.spi.ObjectFactory implementation class (the
> JNDI object factory interface) and registering its name with the "factory"
> parameter.  Documentation is in the JNDI Specification and the
> corresponding Service Provider Interface document, at:
> 
> http://java.sun.com/products/jndi/docs.html

As I said this implementation works fine for TC 4.0.x. and as Craig mentions
the DBCP BasicDataSourceFactory class is a good model for writing your own
implementation.

HTH

Steven

//* 
* VTV Learning Corporation
*        Los Angeles  -  Boston  -  Lisbon
*           (http://www.vtvLearning.com/)
*/


--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to