I am building an application where I need to use connection pooling. I am using Tomcat and mysql. I have previously used connection pooling based on an example, and it used Struts GenericDataSource. This worked well, however I read that it is not production quality, so I am trying to modify it.

Because Tomcat 4.1 now included the commons dbcp, I thought that I will just replace Struts's GenericDataSource with dbcp's BasicDataSource. I am trying not to modify the server.xml and include the parameters for the servlet in the web.xml

The problem is that my java file does not find the org.apache.commons.dbcp.BasicDataSource. All the commons jar files are in the common/lib directory of tomcat. I also placed them in the classpath and in the applications lib directory (just in case)

Can anyone help?

My code looks like this and the DBInitServlet is initialised when the application is uploaded. This and all parameters are specified in the web.xml

package dbase;

//From Beginning JSP Web Development, 2001 Wrox, ISBN 1861002-09-2

import javax.servlet.http.HttpServlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import java.sql.SQLException;
import java.sql.Connection;
import javax.sql.DataSource;
//import org.apache.struts.util.GenericDataSource;

import org.apache.commons.dbcp.BasicDataSource;

public class DBInitServlet extends HttpServlet {

public void init(ServletConfig config) throws ServletException {

try {
BasicDataSource ds = new BasicDataSource();

ds.setDriverClassName(getInitParameter("driverClas s"));
ds.setMaxActive(Integer.parseInt(getInitParameter( "maxActive")));
ds.setMaxWait(Integer.parseInt(getInitParameter("m axWait")));



} catch (SQLException e) {
throw new ServletException("Unable to open datasource");


package dbase;

import java.sql.SQLException;
import java.sql.Connection;
import javax.sql.DataSource;

public class ConnectionPool {

private DataSource ds;
private static ConnectionPool self;

private ConnectionPool(DataSource ds) {
this.ds = ds;

public static void init(DataSource ds) {
self = new ConnectionPool(ds);

public static ConnectionPool getInstance() {
if (self == null) {
throw new IllegalStateException("Pool not initialised");
return self;

public Connection getConnection() throws SQLException {
return (ds.getConnection());


Thank you, Marika Ludmann