Meaningless Drivel is fun!
The moose likes Tomcat and the fly likes DBCP Problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "DBCP Problems" Watch "DBCP Problems" New topic

DBCP Problems

simon sew

Joined: Aug 08, 2005
Posts: 2
Been cracking my head for the past few days just to get the mysql database connection pooling to work. Non of the examples I view or experiment works.

Plz help me.

My current configurations :

Mysql - 4.1.10a-nt
Connector j - 3.1.16
Tomcat - 5.59
SQL Database name - met
Included all the necessary jar files into apache lib folder.

My server.xml configuration :

<Context path="/gsm_server" docBase="C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\gsm_server"
debug="5" reloadable="true" crossContext="true">

<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_DBTest_log." suffix=".txt"

<Resource name="jdbc/metDB"

<ResourceParams name="jdbc/metDB">











My web.xml configuration :

<?xml version="1.0" encoding="ISO-8859-1"?>
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
<description>DB Pooling</description>
<description>DB Connection</description>

My java example :

Hashtable env = new Hashtable();

Context initialContext = new InitialContext(env);
DataSource datasource = (DataSource) initialContext.lookup("java:comp/env/jdbc/metDB");

The errors I get :

javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.commons.dbcp.BasicDataSourceFactory [Root exception is java.lang.ClassCastException: org.apache.commons.dbcp.BasicDataSourceFactory]
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)

Anything else that I missed out ?
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Hashtable env = new Hashtable();

Why do you need this?

Have you tried -

Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/metDB");

as shown on -
JNDI Datasource HOW-TO

The future is here. It's just not evenly distributed yet. - William Gibson
Sonny Gill LinkedIn
I agree. Here's the link:
subject: DBCP Problems
It's not a secret anymore!