aspose file tools*
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
JavaRanch » Java Forums » Products » Tomcat
Bookmark "DBCP Problems" Watch "DBCP Problems" New topic
Author

DBCP Problems

simon sew
Greenhorn

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"
timestamp="true"/>

<Resource name="jdbc/metDB"
auth="Container"
type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/metDB">
<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>watever</value>
</parameter>
<parameter>
<name>password</name>
<value>watever</value>
</parameter>


<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>


<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/met?autoReconnect=true</value>
</parameter>

<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>

<parameter>
<name>removeAbandonedTimeout</name>
<value>60</value>
</parameter>

<parameter>
<name>logAbandoned</name>
<value>true</value>
</parameter>

</ResourceParams>
</Context>

My web.xml configuration :

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<description>DB Pooling</description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/metDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>



My java example :

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.commons.dbcp.BasicDataSourceFactory");

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 ?
TQ
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211


Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.commons.dbcp.BasicDataSourceFactory");


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
Consultant @ Xebia. Sonny Gill Tweets
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DBCP Problems