国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
博客園 - 喻祥,性情中人 - resin連接池
RESIN連接池
===================
/***************************** * 數(shù)據(jù)庫連接 bean ,用來連接 resin 的連接池 *****************************/package net.asales.mysql;import java.sql.Connection;import java.sql.Statement;import java.sql.ResultSet;import java.sql.SQLException;import javax.sql.DataSource;import javax.naming.Context;import javax.naming.InitialContext;public class DBConnection { private Connection conn = null; private Statement stmt = null; private ResultSet rs = null; private int resultNum = 0; /** * 構(gòu)造函數(shù) * 找到數(shù)據(jù)源,并用這個(gè)數(shù)據(jù)源創(chuàng)建連接 */ public DBConnection() { try { Context env = new InitialContext(); DataSource pool = (DataSource) env.lookup        ("java:comp/env/jdbc/asales"); if (pool == null) throw new Exception("jdbc/asales is         an unknown DataSource"); conn = pool.getConnection(); stmt = conn.createStatement(); } catch (Exception e) { System.out.println("naming:" + e.getMessage()); } } /** * 執(zhí)行SQL語句:查詢記錄 * @param sql SQL語句 * @return ResultSet 記錄集 */ public ResultSet executeQuery(String sql) { rs = null; try { rs = stmt.executeQuery(sql); } catch(SQLException se) { System.out.println("Query error:" + se.getMessage()); } return rs; } /** * 執(zhí)行SQL語句 :插入與更新記錄 * @param sql SQL語句 * @return int resultNum 更新的記錄數(shù) */ public int executeUpdate(String sql) { resultNum=0; try { resultNum = stmt.executeUpdate(sql); } catch (SQLException se) { System.err.println("Update error:" + se.getMessage()); } return resultNum; } /** * 關(guān)閉連接 */ public void close() { try { if (rs != null) { rs.close(); rs = null; } if (stmt != null) { stmt.close(); stmt = null; } if (conn != null) { conn.close(); conn = null; } } catch (SQLException se) { System.out.println("close error: " + se.getMessage()); } }}
===================
以下是RESIN配置文件中關(guān)于數(shù)據(jù)源的配置例:
<resource-ref> <res-ref-name>jdbc/asales</res-ref-name> <res-type>javax.sql.DataSource</res-type> <init-param driver-name="org.gjt.mm.mysql.Driver"/> <init-param url="jdbc:mysql://localhost:3306/asales"/> <init-param user="root"/> <init-param password=""/> <init-param max-connections="20"/> <init-param max-idle-time="30"/></resource-ref>
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Hello World Portlet Tutorial
技術(shù)1:在HttpServlet init()方法中緩存數(shù)據(jù)
Servlet中的過濾器(攔截器)Filter與監(jiān)聽器Listener的作用和區(qū)別
tomcat中的開發(fā)應(yīng)用系統(tǒng)常見的配置
java使用InitialContext以及JDBC 工具類庫
JDBC+tomcat6.0+mysql5.1配置數(shù)據(jù)源
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服