When intstalling Tomcat v4.1 and Struts 1.1 and MySQL on my machine, I ran into an assortment of problems one of which was trying to get the connection pooling to work with Tomcat v4.x. After searching around the web with google and looking through the documentation again and again I found the problem. So I documented for the next time I need to set up the environment.
Below I have outlined the steps I used to put the environment together and it does work! If you have any questions, reach out...
Your server.xml file should contain the following resource and resource parameters. You should replace the necessary parameters based on the database driver you are using. In this example, I am using the MySQL Database drivers.
<Resource auth="Container" name="jdbc/MySQLDB" scope="Shareable" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/MySQLDB">
<parameter>
<name>validationQuery</name>
<value>select * from data</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost/testDB</value>
</parameter>
<parameter>
<name>password</name>
<value>test</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>4</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>org.gjt.mm.mysql.Driver</value>
</parameter>
<parameter>
<name>username</name>
<value>test</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
</ResourceParams>
Your web.xml should also contain the same resource information for the data
source
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/MySQLDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
And the most important step is the necessary jar files. THEY MUST BE JAR AND NOT ZIP FILES. The following files should be in your CATALINA_HOME\common\lib. All of these files can be found here http://jakarta.apache.org/commons/index.html
commons-pool.jar
commons-dbcp.jar
commons-collections.jar
The jar file containing the JDBC driver should also be included in the same directory.
Most of this information was available on the Tomcat Website I just consolidated
the information for clarity. You can review the following documents for completeness.
%CATALINA_HOME%\webapps\tomcat-docs\jndi-datasource-examples-howto.html
%CATALINA_HOME%\webapps\tomcat-docs\jndi-resources-howto.html