快崩溃了~数据库连接池问题:Cannot create JDBC driver of class '' for connect URL 'null'
我的数据库连接池的设置如下:
name="jdbc/mysql"
type="javax.sql.DataSource"
maxActive="4"
maxIdle="2"
username="sa"
maxWait="5000"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
password="123456"
url="jdbc:sqlserver://localhost:1433; DatabaseName=EdocServer_db"
我用的是sqlserver 2005 tomcat5.5的 用eclipse建了一个Dynamic Web Project 名为MyWeb 在下面建立了一个测试数据库连接的testdb.jsp,代码如下:
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="javax.naming.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="java.sql.*" %>
<html>
<head>
<title>JDBC Test</title>
</head>
<body>
<%
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
ResultSetMetaData md=null;
try
{
Context initCtx=new InitialContext();
DataSource ds=(DataSource)initCtx.lookup("java:comp/env/jdbc/mysql");
if(ds!=null)
{
out.println("已经获得DataSource");
out.println(ds.toString());
conn=ds.getConnection();//每次运行到这里就出错了 就抛出异常:Cannot create
//JDBC driver of class '' for connect URL 'null'
stmt=conn.createStatement();
out.println("aa");
rs=stmt.executeQuery("select * from userinfo");
md=rs.getMetaData();
out.println("<table border=1>");
out.println("<tr>");
for(int i=0;i<md.getColumnCount();i++)
{
out.println("<td>"+md.getColumnName(i+1)+"</td>");
}
while(rs.next())
{
out.println("<tr>");
out.println("<td>"+rs.getString(1)+"</td>");
out.println("<td>"+rs.getString(2)+"</td>");
out.println("<td>"+rs.getString(3)+"</td>");
out.println("<td>"+rs.getString(4)+"</td>");
out.println("</tr>");
}
out.println("</table>");
conn.close();
}
}
catch(Exception e)
{
out.println(e.toString());
System.out.println(e.toString());
}
%>
</body>
</html>
在%TOMCAT_HOME%/conf/Catalina/localhost下新建一个与我web文件夹同名的xml文件,即MyWeb.xml
内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<Contex