数据库连接池的问题(c3p0),很棘手,项目很紧,高手帮帮忙,严重感谢!!!
1.在server.xml中 <Context> </Context> 内加 <Resource /> ,完整的示例:
<Context path= "/test " docBase= "C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\test " debug= "5 " reloadable= "true " crossContext= "true ">
<Resource auth= "Container " driverClass= "com.mysql.jdbc.Driver "
maxPoolSize= "50 " minPoolSize= "2 " acquireIncrement= "2 "
name= "jdbc/connPool " user= "root " password= "888 "
factory= "org.apache.naming.factory.BeanFactory "
type= "com.mchange.v2.c3p0.ComboPooledDataSource "
jdbcUrl= "jdbc:mysql://localhost:3306/user " />
</Context>
2.在web.xml添加:
<resource-ref>
<description> DB Connection </description>
<res-ref-name> jdbc/connPool </res-ref-name>
<res-type> javax.sql.DataSource </res-type>
<res-auth> Container </res-auth>
</resource-ref>
3.测试页面testConnPool.jsp
<%@ page language= "java " pageEncoding= "UTF-8 "%>
<%@ taglib uri= "http://java.sun.com/jsp/jstl/sql " prefix= "sql " %>
<%@ taglib uri= "http://java.sun.com/jsp/jstl/core " prefix= "c " %>
<sql:query var= "rs " dataSource= "jdbc/connPool ">
select id, typename from text
</sql:query>
<html>
<head>
<title> DB Test Conn Pool c3p0 and Jndi </title>
</head>
<body>
<h2> Results </h2>
<c:forEa