How do I set up DBCP for Tomcat 5.5 and Eclipse?
I'm experimenting with Struts at the moment and I need to set up a D connection pool.
I've tried to read around on what I need to do and I've found references to a context.xml file, or at least a Context element that sits in my server.xml.
As I'm keen to keep things compartmentalised, I understand that I can add a context.xml file under my Web-Inf for each web application. This is my preferred solution.
I'm a bit of a novice when it comes to configuring all this (give me a configured system and I'm happy as Larry)...
I've tried adding the context.xml under web-inf, I've tried renaming it to StrutsTest (the name of my app). Each time, I've included the following:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/StrutsTest" docBase="StrutsTest"
debug="5" reloadable="true" crossContext="true">
<!-- THIS IS NEW -->
<Resource name="jdbc/TestDB"
auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/TestDB">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
<parameter>
<name>username</name>
<value>marklawford</value>
</parameter>
<parameter>
<name>password</name>
<value>mysql</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/mysql_test?autoReconnect=true</value>
</parameter>
</ResourceParams>
<!-- END OF NEW -->
</Context>
Context initContext =new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/TestDB");
Connection conn =null;
try{
conn = ds.getConnection();
System.out.println(conn.getMetaData().getCatalogTerm());
}catch(Exception e){
e.printStackTrace();
}
I've also have the following in my web.xml:
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
I get an org.apache.tomcat.dbcp.dbcp.BasicDataSource instance, but I then get the message:
"Cannot create JDBC driver of class '' for connect URL 'null'".
Where is my disconnect? What is it I'm not doing right?

