tomcat6.0配連接池

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("失敗");

%>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章