wood burning stoves*
The moose likes JDBC and the fly likes Eclipse+Tomcat+JNDI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Eclipse+Tomcat+JNDI" Watch "Eclipse+Tomcat+JNDI" New topic


Ken Sampson
Ranch Hand

Joined: Sep 26, 2007
Posts: 45

I am trying to execute a simple Servlet program using JNDI and DB2 ON Eclipse platform. There is no problem in executing the problem without using Eclipse. On using Eclipse I get the following error:

Cannot create JDBC driver of class '' for connect URL 'null'
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1150)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at TestDB.doGet(TestDB.java:20)

I know this query has been posted many times but I am very much confused as none of the solutions proposed have worked for me hence posting this once again.

The name of my application is TestDB which resides in the context directory TomcatProject.

Here is my web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"




I have created a separate META-INF folder along with the WEB-INF folder where I have placed Context.xml file which is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<Context path="\TomcatProject" docBase="C:\eclipse-SDK\TomcatProject">
<Resource name="jdbc/abc" auth="Container"
type="javax.sql.DataSource" username="db2admin" password="db2admin"
driverClassName="com.ibm.db2.jcc.DB2Driver" url="jdbc:db2:SAMPLE" maxActive="8" maxIdle="4" />

Here is the sample code:

Context ctx = new InitialContext();
Context env = (Context)ctx.lookup("java:comp/env");

DataSource ds = (DataSource) env.lookup("jdbc/abc");
System.out.println("DataSource found successfully ... ");

Connection conn = ds.getConnection();
System.out.println("Connection established successfully ... ");

Please let me know if there is any solution to get around this problem. If anybody has executed any JNDI code using Eclipse platform and Tomcat then please let me know the steps to be executed.

Ken Sampson
I agree. Here's the link: http://aspose.com/file-tools
subject: Eclipse+Tomcat+JNDI
Similar Threads
DataSource Invalid
TOMCAT 5.5.4 + Datasource in ROOT not working
Configure tomcat resource factory
Struts, ''dataSource'' is null
MySQL Error - no driver