tomcat中设置mysql连接池
作者: 文章来源:
发布日期:2007年03月18日
我用的是tomcat5.5.17
第一步:
编辑$TOMCAT_HOME/conf目录中server.xml文件,在</HOST>标签前插入
<Context path="/testDS" docBase="testDS"
debug="5" reloadable="true" crossContext="true">
<Resource
name="jdbc/conMysql"
type="javax.sql.DataSource"
password="password"
driverClassName="com.mysql.jdbc.Driver"
maxIdle="2"
maxWait="5000"
username="root"
url="jdbc:mysql://127.0.0.1:3306/gz"
maxActive="8"/>
</Context>
第二步:编辑$TOMCAT_HOME/webapps/your_web_project/web.xml文件,在</web-app>前插入
<resource-ref>
<description>Tomcat Datasource</description>
<res-ref-name>jdbc/conMysql</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
第三步:编辑测试用jsp文件
<%
DataSource ds = null;
try{
InitialContext ctx=new InitialContext();
ds=(DataSource)ctx.lookup("java:comp/env/jdbc/mysql");
Connection conn = ds.getConnection();
}catch(Exception e){}
%>
第四步:部署并运行