aspose file tools*
The moose likes Servlets and the fly likes Tomcat DataSource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Tomcat DataSource" Watch "Tomcat DataSource" New topic
Author

Tomcat DataSource

Paolo Metafune
Ranch Hand

Joined: Aug 22, 2005
Posts: 34
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.
kesava chaitanya
Ranch Hand

Joined: Aug 15, 2001
Posts: 140
server not able to find classes12.zip. u put classes12.zip or classes12.jar in the classpath
Paolo Metafune
Ranch Hand

Joined: Aug 22, 2005
Posts: 34
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

Joined: Aug 22, 2005
Posts: 34
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.
Ponraj Ram
Greenhorn

Joined: Sep 15, 2005
Posts: 12
Hi Paolo Metafune,
Can you please explain the solution elaborately with your code.

Thanks in Advance.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tomcat DataSource
 
Similar Threads
Tomcat Database Connection Pooling Error
JNDI Connection with Oracle (Problem with NullPointerException)
JNDI in webapps
No suitable driver error when configuring JDBC datasource for Tomcat and Struts
DBCP => Cannot create JDBC driver of class '' for connect URL 'null'