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.*"%>
<HTML>
<HEAD>
<TITLE>Get data with JNDI connection</TITLE>
</HEAD>
<BODY>
<CENTER>
<FONT SIZE = 5 COLOR = blue>Get data with JNDI connection</FONT>
</CENTER>
<HR>
<P></P>

<CENTER>
<%
try{
System.out.println("1---------------------------");
String dbName = "java:comp/env/jdbc/ACCM";
System.out.println("2-------------------");
InitialContext ic = new InitialContext();
System.out.println("3---------------------------");
DataSource ds = (DataSource) ic.lookup(dbName);
System.out.println("4---------------------------");
Connection con = ds.getConnection();
System.out.println("5---------------------------");
Statement stmt = con.createStatement();

ResultSet rs;

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

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

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

} catch(Exception ex) {
System.out.println(ex.toString());
}
      %>
</TABLE>
</CENTER>

</BODY>
</HTML>

------------------------------------------------------------------------------------------------

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

1---------------------------
2---------------------------
3---------------------------
4---------------------------

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" "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">

<web-app>

      <display-name>ACCM</display-name>

      <!-- setting db connection configuration -->
      <resource-ref>
            <description>DB Connection</description>
            <res-ref-name>jdbc/ACCM</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
      </resource-ref>
</web-app>
------------------------------------------------------------------------------------------------

The server.xml file under "%JAVA_HOME%/conf" is :
------------------------------------------------------------------------------------------------
.....
<Host>
...
      <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"
      driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
      url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=ACCM;SelectMethod=cursor"/>
                              
      </Context>
      <!--  Database Connection Pool (DBCP) Configurations end   -->
            
</Host>
------------------------------------------------------------------------------------------------

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

Thank for help in advance.

Catherine


jinghueiAsked:
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.

Catherine
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.

__________________________________________________________________
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
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 (rs.next() ){
String userid=rs.getString("userid");
System.out.println(userid) ;
----------------------------------------------------------------------------------------------------

It should be something set incorrectly.


Catherine
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.*" %>
<html>
<head><title>test DriverManager</title>
</head>
<body>
<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>, ");
  }
  out.println("<hr>");
%>
</body>
</html>
-------------------------------------------------------------------------------------
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?

Catherine



jinghueiAuthor Commented:
Any help will be appreciated!

Help!


Catherine
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?

Thanks,

Catherine
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?

Thanks,

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

Help, help!!

I worked pretty hard to get it work!!


Catherine
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"
type="javax.sql.DataSource"
url="jdbc:microsoft:sqlserver://localhost:1433;
DatabaseName=ACCM;user=sa;password=mypassword"
driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
</Context>
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,

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

finally!

Thanks, any guy!

Catherine
DarthModCommented:
PAQed with points (250) refunded

DarthMod
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
JSP

From novice to tech pro — start learning today.