Monday, September 05, 2005

Configure JDBC datasource for Tomcat 5.5.*

1. Do not modify server.xml.
2. Copy JDBC driver, dbcp and collections jars to common/lib.
3. Add the following to your web.xml in your application:


<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4" xsi="http://www.w3.org/2001/XMLSchema-instance" schemalocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >

<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/dbTest</RES-REF-NAME>
<res-type>javax.sql.DataSource</RES-TYPE>
<res-auth>Container</RES-AUTH>
</RESOURCE-REF>
</WEB-APP>

4. Create new context.xml under META-INF and paste the following:

<context reloadable="true" path="/dbtest" debug="5" crosscontext="true" docbase="dbtest">
<logger timestamp="true" suffix=".txt" prefix="localhost_realtorApp_log." classname="org.apache.catalina.logger.FileLogger">
<resource username="joe" password="XXXX" url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true" type="javax.sql.DataSource" auth="Container" name="jdbc/dbTest" driverclassname="com.mysql.jdbc.Driver" maxwait="5000" maxactive="4" maxidle="2">
</context>

No comments: