Dave,
I apologize that these instructions are a little confusing.
First, the "jzos.war" that is references is the sample web application that is now part of the "TomcatSample" download. This package includes a sample Eclipse project that be hot-deploy to Tomcat. It uses the Tomcat "deployer" Ant tasks, and can be used from any IDE that supports Ant with a little setup. The JDBC sample servlet that you are looking for is included.
But if you don't want to use the sample Tomcat project, all you really need to do to use DB2 JDBC connections is to:
1) Update the server.xml as shown in the Tomcat setup how-to
2) Use the sample Tomcat JCL "TCJDBC2", since you are using type-2 drivers
3) Add a "resource reference" to the Tomcat web application context of whatever webapp that you want to connect to DB2. Tomcat 4 requires this to be added to server.xml, but Tomcat 5 allows it to be separate, as with the Tomcat setup instructions. Using the Tomcat ANT deployer, it can also be in a file called "META-INF/context.xml", which is where it is in the TomcatSample application. Here's that file:
Code: Select all
<!--Context for enabling JDBC under Tomcat -
Tomcat 5: Copy this file to <TOMCAT_HOME>/conf/Catalina/localhost
Tomcat 4: Insert this element in server.xml next to the other Context elements.
Note that other changes must be made to server.xml under both versions of tomcat.
See the Tomcat Setup HOW-TO for details -->
<Context path="/jzos" docBase="jzos" reloadable="true">
<ResourceLink name="jdbc/db2" type="com.ibm.db2.jcc.DB2DataSource" global="jdbc/mydb2"/>
</Context>
This should work fine, but it may not be the best for high-performance JDBC servlets, since it doesn't use a JDBC connection pool.
DB2 has a JDBC connection pooling factory, buts it is complicated to setup and doesn't work nearly as well as the Apache "DBCP" pooling classes. The Tomcat docs can show you how to set these up with Tomcat 5.0.x, but it is messy.
If you go with Tomcat 5.5.x, this process has become VERY easy.
You don't even need to add resources to server.xml, everything can be setup in the web application. Here's an example of context.xml for a web app that uses the new DB2 Universal JDBC Drivers (which also support type-4 connections, as shown below). The Universal JDBC drivers are available if you are at DB2 V8 or with V7 and some PTFs.
Code: Select all
<!--Example Context for a Web app under Tomcat 5.5.
Customize with your driver, HOST, PORT, DATABASE, etc.
For more information on configuration, see:
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
Configuration is somewhat different for Tomcat 5.0.X. For example, the "commons-dbcp"
and companion jars need to be present in <CATALINA_HOME>/common/lib. For details, see:
http://tomcat.apache.org/tomcat-5.0-doc/jndi-datasource-examples-howto.html
-->
<Context path="/jzos" reloadable="true">
<Resource name="jdbc/db2" auth="Container" type="javax.sql.DataSource"
maxActive="20" maxIdle="3" maxWait="10000"
username="user" password="password"
driverClassName="com.ibm.db2.jcc.DB2Driver"
url="jdbc:db2://127.0.0.1:446/DBSG"/>
</Context>
This can be adapted to use type-2 connections by changing the URL as per the DB2 documentation.
I hope this helps a little with setting up DB2 JDBC with Tomcat. I hope to update our Tomcat how-tos in the near future to have more clear and complete information.
Kirk
PS> Some sites may wish to continue to define the JDBC JNDI resource in server.xml and then reference it from each webapp context that uses it, since this has the advantange of having a single pool of connections that are shared by several web apps.