tomcat6.0配连接池

来源:互联网 发布:js自动清除缓存 编辑:程序博客网 时间:2024/05/01 05:14

tomcat6.0配连接池

1. Tomcat6根目录下, conf文件夹下面:修改context.xml文件

在<Context>中加入:

<Resource  name="test"        

                     auth="Container"          

                     type="javax.sql.DataSource"          

                    driverClassName="com.mysql.jdbc.Driver"         

                    url="jdbc:mysql://localhost:3306/ajax"          

                    username="root"        

                   password=""        

                   maxActive="10"          

                   maxIdle="3"          

                    maxWait="10000" />

2.本项目的WEB-INF目录下:修改web.xml文件

在<web-app>中加入:

<resource-ref>    

          <description>DB Connection</description>  

          <res-ref-name>test</res-ref-name>   

          <res-type>javax.sql.DataSource</res-type>   

          <res-auth>Container</res-auth>  

</resource-ref>

3.写测试页面

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

 <%@ page import="java.sql.*"%>

<%@ page import="javax.sql.*"%>

<%@ page import="javax.naming.*,org.test.*"%>

 <%  

Context initCtx = new InitialContext();  

DataSource ds=(DataSource)initCtx.lookup("java:comp/env/test");

 Connection conn=ds.getConnection();  

if(conn!=null)  out.println("取得连接  "+conn);

 else   out.println("失败");

%>

原创粉丝点击