Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

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!

Can't create JDBC driver of class ' ' for connect url 'null'

843841Feb 19 2005 — edited Mar 20 2005
I read number of posts in this regard but no luck yet. Spent already 2 days and it's high time i get any help from experts.

Environment what i'm using is: Apache 2, Tomcat 5.5, Netscape 7.2, MsAccess 2003 on windows 2000 machine.

I integrated tomcat and apache as apache doesn't support jsps. I wrote a JSP called test-db.jsp which in turn calls java program TestSQLLoad.java. This TestSQLLoad.java performs dattabase operation, fetches the data from table and that data is displayed on Netscape thro' jsp.

1. test-db.jsp resides in a directory
TOMCAT_HOME/webapps/web/JSP. Contents are as follows:

<%@ page contentType="text/html" import="testpkg.TestSQLLoad"%>

<html>
<head>
<title>DB Test</title>
</head>
<body>

<%
TestSQLLoad tst = new TestSQLLoad();
tst.init();
%>

<h2>Results</h2>
User -> <%= tst.getUser() %>
Pwd -> <%= tst.getPassword() %>
Id -> <%= tst.getID() %>

</body>
</html>

2. TestSQLLoad.java is residing in following
directory. TOMCAT_HOME/webapps/web/classes/testpkg
direcotry. Contents of this file are as follows:

package testpkg;

import javax.naming.*;
import javax.sql.*;
import java.sql.*;

public class TestSQLLoad
{

String user = "Not Connected";
String pwd = "no pwd";
int id = -1;

public void init() {
try{
Context ctx = new InitialContext();
if(ctx == null ) {
throw new Exception("Boom - No Context");
}

Context envCtx = (Context)
ctx.lookup("java:comp/env");
DataSource ds = (DataSource)
envCtx.lookup("jdbc/db1");

if (ds != null) {
Connection conn = ds.getConnection();

if(conn != null) {
user = "Got Connection "+conn.toString();
Statement stmt = conn.createStatement();
String q = "select name, password, id from user";
ResultSet rst = stmt.executeQuery(q);
if(rst.next()) {
user=rst.getString(1);
pwd=rst.getString(2);
id = rst.getInt(3);
}
conn.close();
}
}
}catch(Exception e) {
e.printStackTrace();
}
}

public String getUser() {
return user;
}

public String getPassword() {
return pwd;
}

public int getID()
{
return id;
}
}

3. I created a jar file using testpkg directory & put
it in TOMCAT_HOME/common/lib as well as
TOMCAT_HOME/webapps/web/WEB-INF/lib directory.

4. I created MsAccess database called db1.mdb and put
it in TOMCAT_HOME/webapps/web/db1 directory. I created
a table called user with fields name, password and ID.
ID is the primary key.

5. I included following in the server.xml of
TOMCAT_HOME/conf directory.

<Context path="/db1" docBase="C:/tomcat/webapps/db1"
debug="5" reloadable="true"
crossContext="true">

<GlobalNamingResources>
<Resource name="jdbc/db1" auth="Container"
type="javax.sql.DataSource"

factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
driverClassName="sun.jdbc.odbc.JdbcOdbcDriver"
url="jdbc:odbc://localhost/db1"
maxActive="20" maxIdle="10" maxWait="-1" />
</GlobalNamingResources>
</Context>

6. I included following in context.xml of
TOMCAT_HOME/conf directory.

<DefaultContext>
<ResourceLink global="jdbc/db1" name="jdbc/db1"
type="javax.sql.DataSource"/>
</DefaultContext>

7. I included following in web.xml of
TOMCAT_HOME/conf directory.

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

8. I copied commons-collections-2.1.1.jar,
commons-dbcp-1.2.1.jar and commons-pool-1.2.jar into
TOMCAT_HOME/common/lib directory.

9. I started apache, tomcat and then opened a browser
and typed http://localhost/web/JSP/test-db.jsp.

10. I get following on the browser.

"Results
User -> Not Connected
Pwd -> no pwd
Id -> -1"

11. On the tomcat window where tomcat is running i'm getting following error.

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of cla
ss '' for connect URL 'null'
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDat
aSource.java:780)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSo
urce.java:540)
at testpkg.TestSQLLoad.init(TestSQLLoad.java:27)
at org.apache.jsp.JSP.test_002ddb_jsp._jspService(org.apache.jsp.JSP.tes
t_002ddb_jsp:54)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:325)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:2
95)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:214)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:148)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:306)

at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:385)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:745)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.ja
va:675)
at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:868)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:684)
at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(Unknown Source)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDat
aSource.java:773)
... 24 more

Please help. It will be highly appreciated.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 17 2005
Added on Feb 19 2005
13 comments
1,435 views