环境:5.5以后含5.5版本
在META-INF下建立文件为context.xml
<Context antiResourceLocking="false" privileged="true" >
<Resource name="mysql"
auth="Container"
type="javax.sql.DataSource"
url="jdbc:mysql://localhost:3306/test"
initialSize="2"
maxActive="20"
maxIdle="20"
minIdle="2"
maxWait="10000"
removeAbandoned="true"
username="root"
password="123456"
driverClassName="com.mysql.jdbc.Driver"
/>
</Context>
测试连接池:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="javax.naming.NamingException" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.Context" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<%
javax.sql.DataSource ds = null;
Context ctx = new InitialContext();
ds = (javax.sql.DataSource) ctx.lookup("java:comp/env/mysql");
%>
<%=
ds.getConnection()
%>
</body>
</html>
posted on 2009-05-13 12:18
孤飞燕 阅读(916)
评论(0) 编辑 收藏 所属分类:
Tomcat