ImageVerifierCode 换一换
格式:DOC , 页数:81 ,大小:407KB ,
资源ID:3907631      下载积分:18 金币
快捷注册下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

开通VIP
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.zixin.com.cn/docdown/3907631.html】到电脑端继续下载(重复下载【60天内】不扣币)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

开通VIP折扣优惠下载文档

            查看会员权益                  [ 下载后找不到文档?]

填表反馈(24小时):  下载求助     关注领币    退款申请

开具发票请登录PC端进行申请

   平台协调中心        【在线客服】        免费申请共赢上传

权利声明

1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:0574-28810668;投诉电话:18658249818。

注意事项

本文(ConnectionPooljar数据连接池文件包的制作流程模板.doc)为本站上传会员【精****】主动上传,咨信网仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知咨信网(发送邮件至1219186828@qq.com、拔打电话4009-655-100或【 微信客服】、【 QQ客服】),核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载【60天内】不扣币。 服务填表

ConnectionPooljar数据连接池文件包的制作流程模板.doc

1、 ConnectionPooljar数据连接池文件包的制作流程模板 81 资料内容仅供您学习参考,如有不当或者侵权,请联系改正或者删除。 关于ConnectionPool.jar数据连接池文件包的制作流程 目的: 制作通用型数据连接池文件包, 便于应用于通用工程 结构: 工程包内classes目录内 1.ConnectionPool : 连接池管理程序 |______ConnectionPool.java |______ConnectionWrapper.java |______LogFile.java

2、LogWriter.java |______MakeDateTime.java |______PoolManager.java 2. com : MySql JDBC驱动程序 3. org : MySql JDBC驱动程序 4. net : MSSqlserver JTDS 驱动程序 5. javax : Oracle JDBC 驱动程序 6. oracle : Oracle JDBC 驱动程序 制作流程: 1. 新建一个工程命名为Pool, 在工程内建立一个war模块命名为Poolwar; 2. 在工程内新建class文件, 文件的包

3、起名为ConnectionPool; 3. 依次新建下列文件: ConnectionPool.java、 ConnectionWrapper.java、 LogFile.java、 LogWriter.java、 MakeDateTime.java、 PoolManager.java 4. 将Oracle for JDBC驱动classes12.jar文件用winrar解压缩, 得到javax和oracle两个文件夹, 将这两个文件夹复制到Pool工程内的classes目录下; 5. 将MS-Sqlserver for JDBC驱动jtds-1.2.jar文件用winrar解压缩,

4、得到net这个文件夹, 将这个文件夹复制到Pool工程内的classes目录下; 6. 将MySql for JDBC驱动mysql-connector-java-3.0.16-ga-bin.jar文件用winrar解压缩, 得到com和org两个文件夹, 将这两个文件夹复制到Pool工程内的classes目录下; 7. 如果需要添加其它驱动程序, 可参照4-6进行; 8. 选择JBuilder工具条上Wizards--àArchive Builder ; 9.Archive Builder – Step 1 of 5 : Archive Type 选择Basic( 具体类

5、型含义参考JBuilerX使用手册) ; 10. Archive Builder – Step 2 of 5 : 将Name 和 File 命名为需要的名字, 这里同意将其命名为ConnectionPool, 其它的选项均不做更改; 11.Archive Builder – Step 3 of 5 : 指定结构文件包含内容, 这里不做任何修改; 12.Archive Builder – Step 4 of 5 : 将servlet 选择为 Allway

6、s include all classes and resources; 13.Archive Builder – Step 4 of 5 : 保持默认状态不改变, 按finish完成结构文件的定义; 14.在工程窗口用鼠标右键点 ConnectionPool 结构, 然后选择make 生成结构文件; 使用方法: 1. 将该jar文件添加到 ToolsàConfigure Librarise 中; 2. 新加工程, 在工程 Required Librarise 中添

7、加该库文件; 3. 在工程中新建一个”连接池初始化类”负责建立数据连接; 4. 在工程中新建一属性文件----db.properties, 负责描述数据库驱动及用户信息等, 该属性文件存放的位置在PoolManager.java中定义; 5. 在PoolManager.java中默认为”../ db.properties”,该位置表示在/WEB-INF 目录下; 附录: 文件代码 ************************文件开始*************************** db.properties

8、 //属性文件 *********************************************************** XBDBManager Properties poolname = sqlpool oraclepool 注: 中间以空格分隔 drivers = net.sourceforge.jtds.jdbc.Driver oracle.jdbc.driver.OracleDriver 注: 中间以空格分隔 logfile = d:\\logfile.txt sqlpool.url = jdbc:jtds:sqlserver://10.1.1.

9、2:1433;DatabaseName=pda sqlpool.initconns=50 sqlpool.maxconns=80 sqlpool.user = pda sqlpool.password = pdapass1234 oraclepool.url = jdbc:oracle:thin:@172.168.72.8:1521:infodb oraclepool.initconns=50 oraclepool.maxconns=80 oraclepool.user = tjold oraclepool.password = tjold **************

10、文件结束*************************** ************************文件开始*************************** ConnectionPool.java *********************************************************** package ConnectionPool; import java.io.*; import java.sql.*; import java.util.*; public cl

11、ass ConnectionPool { private String name; private String URL; private String user; private String password; private int maxConns; private int timeOut; private LogWriter logWriter; private int checkedOut; private Vec

12、tor freeConnections = new Vector(); public ConnectionPool(String name, String URL, String user, String password, int maxConns, int initConns, int timeOut, PrintWriter pw, int logLevel) { this.name = name; this.UR

13、L = URL; this.user = user; this.password = password; this.maxConns = maxConns; this.timeOut = timeOut > 0 ? timeOut : 5; logWriter = new LogWriter(name, logLevel, pw); initPool(initConns);

14、 logWriter.log("New pool created", LogWriter.INFO); String lf = System.getProperty("line.separator"); logWriter.log( " url=" + URL + " user=" + user + // " password=" + password

15、 " initconns=" + initConns + " maxconns=" + maxConns + " logintimeout=" + this.timeOut, LogWriter.INFO); logWriter.log(getStats(), LogWriter.INFO); } private void initPool(int initConns)

16、{ for (int i = 0; i < initConns; i++) { try { Connection pc = newConnection(); freeConnections.addElement(pc); } catch (SQLException e)

17、 { } } } public Connection getConnection() throws SQLException { logWriter.log("Request for connection received", LogWriter.DEBUG); try { Connection conn =

18、getConnection(timeOut * 1000); return new ConnectionWrapper(conn, this); } catch(SQLException e) { logWriter.log(e, "Exception getting connection", logWriter.ERROR); throw e;

19、 } } synchronized void wrapperClosed(Connection conn) { freeConnections.addElement(conn); checkedOut--; notifyAll(); logWriter.log("Returned wrapperClosed to pool", LogWriter.INFO);

20、 logWriter.log(getStats(), LogWriter.INFO); } private synchronized Connection getConnection(long timeout) throws SQLException { // Get a pooled Connection from the cache or a new one. // Wait if all are checked out and the max limit

21、 has // been reached. long startTime = System.currentTimeMillis(); long remaining = timeout; Connection conn = null; while ((conn = getPooledConnection()) == null) { try {

22、 logWriter.log("Waiting for connection. Timeout=" + remaining, LogWriter.DEBUG); wait(remaining); } catch (InterruptedException e) { }

23、 remaining = timeout - (System.currentTimeMillis() - startTime); if (remaining <= 0) { // Timeout has expired logWriter.log("Time-out while waiting for connection",

24、 LogWriter.DEBUG); throw new SQLException("getConnection() timed-out"); } } // Check if the Connection is still OK if (!isConnectionOK(conn)) { //

25、 It was bad. Try again with the remaining timeout logWriter.log("Removed selected bad connection from pool", LogWriter.ERROR); return getConnection(remaining); } checkedOut++;

26、 logWriter.log("Delivered getConnection from pool", LogWriter.INFO); logWriter.log(getStats(), LogWriter.INFO); return conn; } private boolean isConnectionOK(Connection conn) { Statement testStmt = null; try {

27、 if (!conn.isClosed()) { // Try to createStatement to see if it's really alive testStmt = conn.createStatement(); testStmt.close(); }

28、 else { return false; } } catch (SQLException e) { if (testStmt != null) { try { testStmt.close();

29、 } catch (SQLException se) { } } logWriter.log(e, "Pooled Connection was not okay", LogWriter.ERROR); return false;

30、 } return true; } private Connection getPooledConnection() throws SQLException { Connection conn = null; if (freeConnections.size() > 0) { // Pick the first Connection in the Vector

31、 // to get round-robin usage conn = (Connection) freeConnections.firstElement(); freeConnections.removeElementAt(0); } else if (maxConns == 0 || checkedOut < maxConns) { conn = newConnectio

32、n(); } return conn; } private Connection newConnection() throws SQLException { Connection conn = null; if (user == null) { conn = DriverManager.getConnection(URL); }

33、 else { conn = DriverManager.getConnection(URL, user, password); } logWriter.log("Opened a new connection", LogWriter.INFO); logWriter.log(getStats(), LogWriter.INFO); return conn; }

34、 public synchronized void freeConnection(Connection conn) { // Put the connection at the end of the Vector freeConnections.addElement(conn); checkedOut--; notifyAll(); logWriter.log("Returned freeConnection

35、 to pool", LogWriter.INFO); logWriter.log(getStats(), LogWriter.INFO); } public synchronized void release() { Enumeration allConnections = freeConnections.elements(); while (allConnections.hasMoreElements()) {

36、 Connection con = (Connection) allConnections.nextElement(); try { con.close(); logWriter.log("release Closed connection", LogWriter.INFO); } catch (SQLException e) {

37、 logWriter.log(e, "release Couldn't close connection", LogWriter.ERROR); } } freeConnections.removeAllElements(); } private String getStats() { return "Total connections: " + (freeCon

38、nections.size() + checkedOut) + " Available: " + freeConnections.size() + " Checked-out: " + checkedOut; } } ************************文件结束*************************** ************************文件开始*************************** ConnectionWrapper.java *********

39、 package ConnectionPool; import java.sql.*; import java.util.*; /** * This class is a wrapper around a Connection, overriding the * close method to just inform the pool that it's available for * reuse again, and the isClosed method to r

40、eturn the state * of the wrapper instead of the Connection. */ class ConnectionWrapper implements Connection { // realConn should be private but we use package scope to // be able to test removal of bad connections Connection realConn; private ConnectionPool

41、pool; private boolean isClosed = false; public ConnectionWrapper(Connection realConn, ConnectionPool pool) { this.realConn = realConn; this.pool = pool; } /** * Inform the ConnectionPool that the ConnectionWr

42、apper * is closed. */ public void close() throws SQLException { isClosed = true; pool.wrapperClosed(realConn); } /** * Returns true if the ConnectionWrapper is closed, false * otherwise.

43、 */ public boolean isClosed() throws SQLException { return isClosed; } /* * Wrapped methods. */ public void clearWarnings() throws SQLException { if (isClosed) {

44、 throw new SQLException("Pooled connection is closed"); } realConn.clearWarnings(); } public void commit() throws SQLException { if (isClosed) { throw new SQLExcept

45、ion("Pooled connection is closed"); } realCmit(); } public Statement createStatement() throws SQLException { if (isClosed) { throw new SQLException("Pooled connection is closed")

46、 } return realConn.createStatement(); } public boolean getAutoCommit() throws SQLException { if (isClosed) { throw new SQLException("Pooled connection is closed");

47、 } return realConn.getAutoCommit(); } public String getCatalog() throws SQLException { if (isClosed) { throw new SQLException("Pooled connection is closed"); }

48、 return realConn.getCatalog(); } public DatabaseMetaData getMetaData() throws SQLException { if (isClosed) { throw new SQLException("Pooled connection is closed"); } return real

49、Conn.getMetaData(); } public int getTransactionIsolation() throws SQLException { if (isClosed) { throw new SQLException("Pooled connection is closed"); } return realConn.getTransactionIsolation(); } public SQLWarning getWarnings() throws SQLException { if (isClosed) { throw new SQLException("Pooled connection is closed"); } return realConn.getWarnings(); } public boolean isReadOnly() th

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服