Error for getting data with JNDI connection--Cannot JDBC driverof class ' ' for connect URL 'null'

I use Tomcat5.5 with JDK1.5.
The jsp file is put under "%JAVA_HOME%/webapps/Root" called JNDI.jsp.

<%@ page contentType="text/html; charset=Big5"
      import="java.sql.*, javax.sql.*, javax.naming.*"%>
<TITLE>Get data with JNDI connection</TITLE>
<FONT SIZE = 5 COLOR = blue>Get data with JNDI connection</FONT>

String dbName = "java:comp/env/jdbc/ACCM";
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup(dbName);
Connection con = ds.getConnection();
Statement stmt = con.createStatement();

ResultSet rs;

rs = stmt.executeQuery("SELECT * FROM dept");

<TABLE  bgcolor=DodgerBlue>
      <TR  bgcolor=SkyBlue>
      while (
            <TR bgcolor=LightGoldenrodYellow>
            <TD><B><%= rs.getString("userid") %></B></TD>
            <TD><B><%= rs.getString("pwd") %></B></TD>
            <TD><B><%= rs.getString("clevel") %></B></TD>

      if(rs != null) rs.close();
      if(stmt != null) stmt.close();
      if(con != null) con.close();

} catch(Exception ex) {



The message of the execution "http://localhost:8080/JNDI.jsp" showed  under Tomcat as following:


org.apache.tomcat.dbcp.dbcp.SQLNestedException:Cannot JDBC driverof class '  '  for connect URL 'null'.
That meant it cannot get to '5'--the connection.

The web.xml file under "%JAVA_HOME%/webapps/Root/WEB-INF" is:
<?xml version="1.0" encoding="Big5"?>

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "">



      <!-- setting db connection configuration -->
            <description>DB Connection</description>

The server.xml file under "%JAVA_HOME%/conf" is :
      <Context path="jdbc/ACCM" docBase="ROOT" debug="5" reloadable="true" crossContext="true">
      <!--  MsSQL Server  -->
      <Resource name="jdbc/ACCM" auth="Container" type="javax.sql.DataSource"
      maxActive="100" maxIdle="30" maxWait="10000"
      username="sa" password="mypassword"
      <!--  Database Connection Pool (DBCP) Configurations end   -->

What is the problem?
It already costs me a lot of time still cannot get it solved.

Thank for help in advance.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jinghueiAuthor Commented:
The error msg should be "Cannot  create JDBC driverof class '  '  for connect URL 'null' ".
Typing error! Sorry.

Mick BarryJava DeveloperCommented:
where are the driver jars installed?
jinghueiAuthor Commented:
under "%JAVA_HOME%/common/lib"
It should be no problem.

Because I use another jsp file to access the sqlserver database works fine.

String str = "jdbc:microsoft:sqlserver://localhost:1433;databasename=ACCM";

Connection conn = DriverManager.getConnection(str,"sa","mypassword");

Statement stmt=conn.createStatement() ;
String qstr="SELECT * FROM dept";
ResultSet rs=stmt.executeQuery(qstr);
while ( ){
String userid=rs.getString("userid");
System.out.println(userid) ;

It should be something set incorrectly.

Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

jinghueiAuthor Commented:
I use another jsp file to test the driver got by the program:
<%@ page contentType="text/html; charset=big5"
    import="java.sql.*, java.util.*" %>
<head><title>test DriverManager</title>
<h2>test DriverManager</h2>
    out.println("Current JDBC Drivers got&#65306;<p>");
  Enumeration enuDriver = DriverManager.getDrivers();
  String strName;
  while (enuDriver.hasMoreElements()) {
     strName = enuDriver.nextElement().getClass().getName();
     out.println("<b>" + strName + "</b>, ");
There is nothing got by the program!!!---driver for MsSqlserver is not got at all!?

I put the have the jars--Msbase.jar, Msutil.jar,Mssqlserver.jar under "%JAVA_HOME%/common/lib",
and also in  in my classpath.

Is there still something missing?


jinghueiAuthor Commented:
Any help will be appreciated!


jinghueiAuthor Commented:
I think the error most likely comes from the "Context" part of the server.xml.
Since I put the jsp file under the "%JAVA_HOME%/webapps/ROOT, what should be set in the "Context" part
and docBase part?

I can put them in some other directory (ex. testDB) . Should I create a module directory for them(ex. webModule1)?
What should be the root directory of the webapp? It should be /testDB or /testDB/webModule1?

I am a newbie in JAVA, I don't quite understand these parts.

Could expert explain them?


jinghueiAuthor Commented:
This should be a basic problem but causes a lot of persons get stuck.
I got stuck for 2 weeks.

I need a clear tutorial for get sqlserver2000 JNDI connection works with Tomcat5.5.

Anybody can help?


jinghueiAuthor Commented:
Why Tomcat is designed so difficult to use?

Help, help!!

I worked pretty hard to get it work!!

jinghueiAuthor Commented:
I reinstall Tomcat 5.5, reinstall JDBC sqlserver driver.
And set the server.xml
<Context path="" docBase="ROOT" debug="0" reloadable="true" crossContext="true">
 <Resource name="jdbc/ACCM" scope="Shareable"
Finally, the jsp program gets to '5--------'.
It means it successfully connect to database.
Cheers! After many hours work.

It still have an error msg--"java.sql.SQLException:[Microsoft
jinghueiAuthor Commented:
It still have an error msg--"java.sql.SQLException:[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]invalid object name 'dept'.

The database 'ACCM' does have a table called 'dept'.

What could be the problem?

Thanks for spending time for me,

jinghueiAuthor Commented:
I change the login name 'sa' to other name, and get it work!


Thanks, any guy!

PAQed with points (250) refunded

Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.