日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

Tomcat5.5 配置mysql数据库连接池

發(fā)布時間:2024/4/14 数据库 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Tomcat5.5 配置mysql数据库连接池 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
環(huán)境:Tomcat5.5.23 Eclipse3.2.2 MyEclipse 5.1.1 GA mysql4.0.16 一、在Server.xml中配置 <Resource name="jdbc/myown" auth="Container" type="javax.sql.DataSource" maxActive="10" maxIdle="3" maxWait="10000" username="root" password="" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/test" /> 放到 </GlobalNamingResources>中。 二、F:\soft\apache-tomcat-5.5.23\conf\Catalina\localhost目錄中新建一個工程名.xml文件,F:\soft\apache-tomcat-5.5.23為tomcat安裝目錄。在工程名.xml中寫下面的內(nèi)容: <Context> <Resource name="jdbc/myown" auth="Container" type="javax.sql.DataSource" maxActive="10" maxIdle="3" maxWait="10000" username="root" password="" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/test" /> </Context> 三、添加數(shù)據(jù)庫驅(qū)動jar文件到F:\soft\apache-tomcat-5.5.23\common\lib與工程web目錄\lib下. 四、寫jsp頁面測試: <%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>

<html>
<body>
<%
DataSource ds = null;
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
InitialContext ctx = null;
try {
ctx = new InitialContext();
ds = (DataSource) ctx.lookup("java:comp/env/jdbc/myown");
conn = ds.getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from users");
while (rs.next()) {
out.println(rs.getString(1) + "");
out.println(rs.getString(2) + "");
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
if (rs != null)
rs.close();
if (stmt != null)
stmt.close();
if (conn != null)
conn.close();
if (ctx != null)
ctx.close();
} catch (SQLException e) {
System.out.println("SQL關(guān)閉異常");
e.printStackTrace();
} catch (NamingException e) {
System.out.println("命名空間關(guān)閉異常");
e.printStackTrace();
}

}
%>

</body>
</html>

總結(jié)

以上是生活随笔為你收集整理的Tomcat5.5 配置mysql数据库连接池的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。