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
Author

Eclipse+Tomcat+JNDI

Ken Sampson
Ranch Hand

Joined: Sep 26, 2007
Posts: 45
Hello,

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

<servlet>
<servlet-name>TestDB</servlet-name>
<servlet-class>TestDB</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>TestDB</servlet-name>
<url-pattern>/testdb</url-pattern>
</servlet-mapping>

<resource-ref>
<res-ref-name>jdbc/abc</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>

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" />
</Context>


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