Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DBCP Problems

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
 
That is a really big piece of pie for such a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic