This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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(
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(
at TestDB.doGet(

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=""




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="" 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:
subject: Eclipse+Tomcat+JNDI