• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Tomcat can't find my JDBC Resource !!!

 
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'

Is the error I get.

When they compiled the latest �stable� Tomcat, did they bother to test it before putting it out?



I looke through the entire google, and through this entire list, and I found lots of people having this problem. Yet, I didn�t find any solutions (that worked for me that is).



Basically, here�s what I have:



I�m running Tomcat 5.0.27 on Java 1.5 beta 2; I am using MySQL 4.1.2



Inside /common/lib/ I have mysql-connector.jar which is 3.0.14 � production version.



Inside my server.xml I have (relevant stuff):



<Host appBase="/home/resk/web" name="resk" autoDeploy="true" unpackWARs="true" liveDeploy="true">



</Host>



Inside my /conf/Catalina/resk I have resk.xml:



<?xml version='1.0' encoding='utf-8'?>

<Context debug="5" displayName="RESK" docBase="ROOT" // BY THE WAY I also tried /home/resk/web/ROOT

path="/" reloadable="false">

<Environment name="data.source.name" type="java.lang.String" value="java:comp/env/jdbc/RESK"/> // BTW I tried without this line

<Resource auth="Container" name="jdbc/RESK"

type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/RESK">

<parameter>

<name>url</name>

<value>jdbc:mysql://127.0.0.1:3306/resk?autoReconnect=true</value>

</parameter>

<parameter>

<name>maxIdle</name>

<value>2</value>

</parameter>

<parameter>

<name>maxActive</name>

<value>10</value>

</parameter>

<parameter>

<name>driverClassName</name>

<value>com.mysql.jdbc.Driver</value>

</parameter>

<parameter>

<name>maxWait</name>

<value>10000</value>

</parameter>

<parameter>

<name>removeAbandoned</name>

<value>true</value>

</parameter>

<parameter>

<name>username</name>

<value>resk</value>

</parameter>

<parameter>

<name>factory</name>

<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>

</parameter>

<parameter>

<name>removeAbandonedTimeout</name>

<value>60</value>

</parameter>

<parameter>

<name>password</name>

<value>RESK</value>

</parameter>

</ResourceParams>

</Context>



Inside my /home/resk/web/ROOT/WEB-INF/ I have web.xml (relevant stuff):



<web-app version="2.4"

xmlns="http://java.sun.com/xml/ns/j2ee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >



<resource-ref>

<description>DB Connection</description>

<res-ref-name>jdbc/RESK</res-ref-name>

<res-type>javax.sql.DataSource</res-type>

<res-auth>Container</res-auth>

</resource-ref>



<!-- Used for startup primarly. Kepping things in one place. -->

<env-entry>

<env-entry-name>data.source.name</env-entry-name>

<env-entry-type>java.lang.String</env-entry-type>

<env-entry-value>java:comp/env/jdbc/RESK</env-entry-value>

</env-entry>





Now, here�s how I load the data source (relevant part of the class):



public class Manager

{

DataSource ds;

static Manager instance;



private Manager()

{

try

{

// This is all the web.xml properties

InitialContext context = new InitialContext();

dbDataSource = (String)context.lookup("java:comp/env/data.source.name");

ds = (DataSource) new InitialContext().lookup(dbDataSource);

}

catch ( NamingException e )

{

Logger.getLogger("problem").fatal("Unable to load database data source!",e);

ds = null; // This will throw enough exceptions to notice the problem

}

}



/**

* @return instance of the Manager.

*/

public static Manager getInstance()

{

if (instance == null) instance = new Manager();

return instance;

}



/**

* @return Connection from the pool. Make sure to close it when done.

*/

public synchronized Connection getConnection() throws SQLException

{

return ds.getConnection();

}



}





Now, interesting thing to note. If I look at my catalina_log.2004-07-11.txt, I will find the following:



2004-07-11 20:47:47 NamingContextListener[/Catalina/resk/]: Resource parameters for jdbc/RESK = ResourceParams[name=jdbc/RESK, parameters={url=jdbc:mysql://127.0.0.1:3306/resk?autoReconnect=true, maxIdle=2, maxActive=10, driverClassName=com.mysql.jdbc.Driver, maxWait=10000, removeAbandoned=true, username=resk, factory=org.apache.commons.dbcp.BasicDataSourceFactory, removeAbandonedTimeout=60, password=RESK}]

2004-07-11 20:47:47 NamingContextListener[/Catalina/resk/]: Adding resource ref jdbc/RESK

2004-07-11 20:47:47 NamingContextListener[/Catalina/resk/]: ResourceRef[className=javax.sql.DataSource,factoryClassLocation=null,factoryClassName=org.apache.naming.factory.ResourceFactory,{type=scope,content=Shareable},{type=auth,content=Container},{type=url,content=jdbc:mysql://127.0.0.1:3306/resk?autoReconnect=true},{type=maxIdle,content=2},{type=maxActive,content=10},{type=driverClassName,content=com.mysql.jdbc.Driver},{type=maxWait,content=10000},{type=removeAbandoned,content=true},{type=username,content=resk},{type=factory,content=org.apache.commons .dbcp.BasicDataSourceFactory},{type=removeAbandonedTimeout,content=60},{type=password,content=RESK}]

2004-07-11 20:47:47 NamingContextListener[/Catalina/resk/]: Adding environment entry data.source.name

2004-07-11 20:47:47 NamingContextListener[/Catalina/resk/]: Resource parameters for UserTransaction = null



Looking through this stuff it�s obvious that my resource IS found, and that it IS loaded. Yet, somehow, My application does not see it�



Anybody knows why? Any help will be greatly appreciated�
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic