Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JNDI+Tomcat+Eclipse

843859Dec 27 2007 — edited Dec 27 2007
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 24 2008
Added on Dec 27 2007
1 comment
216 views