• 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
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Tomcat DataSource

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've configured a datasource for oracle under tomcat 5, but when i try to get a connection i receive this error "org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null', cause: No suitable driver".When i debug my code i note that the datasource returned after lookup has null properties (for instance the driver class property is null).

This is my web.xml:
************************
<resource-ref>
<description>Oracle Datasource example</description>
<res-ref-name>jdbc/MyOracleDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

************************

This is my servlet code:
************************
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:comp/env");
String s = "jdbc/MyOracleDataSource";
DataSource ds = (DataSource)envContext.lookup(s);
System.out.println(s);
Connection conn = ds.getConnection();
************************

and this is my server.xml:
************************

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

<ResourceParams name="jdbc/MyOracleDataSource">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>4</value>
</parameter>
<parameter>
<name>password</name>
<value>pronto</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc racle:thin:@ihx0074:1521:INA</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
<parameter>
<name>username</name>
<value>cassa</value>
</parameter>
</ResourceParams>

************************

Can anyone tell me why it doesn't work ?
Thank you.
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
server not able to find classes12.zip. u put classes12.zip or classes12.jar in the classpath
 
Paolo Metafune
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Classes12.zip is already in the classpath.
What i noted is that the datasource returned after lookup is not correct. I debugged my code and the datasource returned has all the properties = null.
If you look again at this error message "Cannot create JDBC driver of class '' for connect URL 'null', cause: No suitable driver", it seem that datasource can't load the driver because the driver to load is not configured (driver of class ''). So it is like if my servlet couldn't reach the datasource definition in server.xml.
I deleted the datasorce definition from this file (server.xml) and my code continue to run with the same error. I mean that i have the same result if i define the datasaource and if don't define.

Bye,
 
Paolo Metafune
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I resolved my problem.
The error was a wrong configuration in server.xml. I didn' put the data source configurationt under the Context element for my web application. In addition to nesting Context elements inside a Host element in server.xml, is also possible to store them in individual files (with a ".xml" extension) in the $CATALINA_HOME/conf/[enginename]/[hostname]/ directory. This is recommended in Tomcat 5 and so i did.
Now myDataSource works.
Bye.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paolo Metafune,
Can you please explain the solution elaborately with your code.

Thanks in Advance.
 
Pay attention! Tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic