我用的是tomcat7.0.11在tomcat的webapps文件里放置了一个名为“wm”的项目在项目的WEB-INF文件里的context.xml和web.xml分别进行了如下配置
<?xml version="1.0" encoding="ISO-8859-1"?>
<Context path="/appName" docBase="appName"
    debug="5" crossContext="true" reloadable="false"
    cachingAllowed="true" cacheMaxSize="20480"
    cacheTTL="10000">
    <Resource name="jdbc/mysql" auth="Container" removeAbandoned="true"
    removeAbandonedTimeout="60" logAbandoned="true"
    type="javax.sql.DataSource" maxActive="30" maxIdle="10"
    maxWait="-1" username="sa" password=""
    driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
    url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db" />
    </Context>
--------------------------------------------------------------
<resource-ref>
        <description>DB Connection</description>
        <res-ref-name>jdbc/mysql</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
-------------------------------------------------------------------
然后在mw里面放人了一个测试文件TextDBPool.jsp,代码如下<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<html>
  <head>cs</head>
  <body>
  <%
  Context context=(Context)new InitialContext();
  DataSource dataSource=(DataSource) context.lookup("java:comp/env/jdbc/mysql");
  for(int i=0;i<40;i++)
  {
   Connection conn=dataSource.getConnection();
   try{
   conn.close();
   }catch(Exception e){
   e.printStackTrace();
   }
  
  }
  out.print("ok");
  %>
  </body>
  </html>
------------------------------------------------------
启动浏览器后,在地址栏输入“http://localhost:8080/mw/TestDBPool.jsp”后返
回如下界面HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: An exception occurred processing JSP page /TestDBPool.jsp at line 1310:   DataSource dataSource=(DataSource) context.lookup("java:comp/env/jdbc/mysql");
11:   for(int i=0;i<40;i++)
12:   {
13:    Connection conn=dataSource.getConnection();
14:    try{
15:    conn.close();
16:    }catch(Exception e){
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:553)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:442)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause javax.servlet.ServletException: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:911)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:840)
org.apache.jsp.TestDBPool_jsp._jspService(TestDBPool_jsp.java:89)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
org.apache.jsp.TestDBPool_jsp._jspService(TestDBPool_jsp.java:71)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause java.lang.NullPointerException
sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(Unknown Source)
sun.jdbc.odbc.JdbcOdbcDriver.knownURL(Unknown Source)
sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(Unknown Source)
java.sql.DriverManager.getDriver(Unknown Source)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
org.apache.jsp.TestDBPool_jsp._jspService(TestDBPool_jsp.java:71)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.11 logs.----------------------------------------------------------------------------------------------------
不知道错在哪里了

解决方案 »

  1.   

    org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
      

  2.   

    LZ看一下这个能不能解决吧
    http://www.blogjava.net/flustar/archive/2007/04/17/111362.html
      

  3.   

    1.看看tomcat里有没有mssql的driver,如果没有就去网上载一个
    2.<Resource name="jdbc/mysql" auth="Container" removeAbandoned="true"
    是这样写吗?看起来好像mysql而不是mssql
      

  4.   

    jar放在LIB里了没
    URL

    数据库字符串
    有没有写对啊
    MS2000 和 MS2005不一样滴。MS2000要打上SP4补丁。
      

  5.   

    context.xml不在WEB-INF...
    在META-INF...
      

  6.   

    这个是名字,应该没关心吧,我改成mssql也没用啊。