在看《精通JSP》-张新曼著时的连接池问题
环境:Tomcat 5.5.17中文版、
数据库驱动:mysql-connector-java-3.1.12-bin.jar
一、
按照书上的说明,在Tomcat的管理页面中配置了数据源,在server.xml文件生成内容如下: <Resource
name= "jdbc/mysql "
type= "javax.sql.DataSource "
password= "123456 "
driverClassName= "com.mysql.jdbc.Driver "
maxIdle= "40 "
maxWait= "5000 "
username= "root "
url= "jdbc:mysql://localhost:3306/netshop "
maxActive= "40 "/>
二、
web.xml配置内容如下:
<resource-ref>
<description> mysqlDB Connection </description>
<res-ref-name> jdbc/mysql </res-ref-name>
<res-type> javax.sql.DataSource </res-type>
<res-auth> Container </res-auth>
</resource-ref>
三、
context.xml文件内容如下:
<?xml version= "1.0 " encoding= "UTF-8 "?>
<Context>
<ResourceLink name= "jdbc/mysql " global= "jdbc/mysql " type= "javax.sql.DataSource "/>
</Context>
四、JSP文件如下:
<%@ page contentType= "text/html;charset=gb2312 " %>
<%@ page import= "java.sql.* "%>
<%@ page import= "javax.sql.* "%>
<%@ page import= "javax.naming.* "%>
<%@ page session= "false " %>
<html>
<head>
<title> MySQL 数据源测试 </title>
<center>
<%
out.print( "MySQL 数据源测试开始... "+ " <br/> ");
DataSource ds = null;
try{
InitialContext ctx=new InitialContext();
ds=(DataSource)ctx.lookup( "java:comp/env/jdbc/mysql ");
Connection conn = ds.getConnection();
conn.close();
out.print( "MySQL 数据源测试成功! ");
}
catch(Exception ex){
out.print( "出现意外,信息是: "+ex.getMessage());
ex.printStackTrace();
}
%>
</center>
</head>
</html>
五、产生的错误如下:
org.apache.tomcat.dbcp.dbcp.
SQLNestedException: Cannot create JDBC driver of class ' ' for connect URL 'null '