You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by red phoenix <ro...@gmail.com> on 2006/04/04 05:28:50 UTC

JNDI configure question

I use tomcat 5.5.16,and my database is Microsoft Access 2000,and I have
configured ODBC as SMS in windows,then I configure JNDI like follows:

/*\tomcat\conf\server.xml*/
<Host name="localhost" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
   <Context path="/" docBase=""
        debug="5" reloadable="true" crossContext="true">
        <Resource name="jdbc/abc" auth="Container"
          type="javax.sql.DataSource" driverClassName="
sun.jdbc.odbc.JdbcOdbcDriver"
          url="jdbc:odbc:SMS"
          username="administrator" password="123" maxActive="20"
maxIdle="10" maxWait="-1"/>
    </Context>
</Host>

/*\tomcat\webapps\test\WEB-INF\web.xml*/
<?xml version="1.0" encoding="ISO-8859-1"?>

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

  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Tomcat
  </description>

<!-- JSPC servlet mappings start -->

    <servlet>
        <servlet-name>org.apache.jsp.index_jsp</servlet-name>
        <servlet-class>org.apache.jsp.index_jsp</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>org.apache.jsp.index_jsp</servlet-name>
        <url-pattern>/index.jsp</url-pattern>
    </servlet-mapping>
<resource-ref>
        <description>DB Connection</description>
  <res-ref-name>jdbc/abc</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
    </resource-ref>
<!-- JSPC servlet mappings end -->

</web-app>

My jsp file is follows:
<%@page import="java.sql.*"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="javax.naming.*"%>
<html>
<body>
<%
 try{
  Context initCtx=new InitialContext();
  System.out.println("ok1");
  DataSource db = (DataSource)initCtx.lookup("java:comp/env/jdbc/abc");
  System.out.println("db="+db);
  Connection conn = db.getConnection();
  System.out.println("conn="+conn);
  Statement stmt = conn.createStatement();
  ResultSet rs = stmt.executeQuery("SELECT * FROM abc");
  out.println("User-list"+"<br>");
  while(rs.next()){
   out.print(rs.getString(1)+"<br>");
  }
  rs.close();
  stmt.close();
  conn.close();
 }catch(Exception e){
  out.print(e);
 }
%>
</body>
</html>

When I run my jsp,it raise following error:
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of
class '' for connect URL 'null'

I want to know where is error? How to correct it?