国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

連接池管理的代碼

2019-11-18 12:11:28
字體:
供稿:網(wǎng)友

  the detail pool management code
  DBConnectionManager.java
  
  package com.coa.cim.database;
  
  /**
  *

Title: CIM SYSTEM


  *

Description: The Customer Infomation Managment System


  *

Copyright: Copyright (c) 2002


  *

Company: COA Sci&Tech


  * @author Mula Liu
  * @version 1.0
  */
  
  import java.sql.*;
  import java.util.*;
  import java.io.*;
  
  public class DBConnectionManager {
  
  
  PRivate static DBConnectionManager instance=null;
  private DBConnectionPool pool;
  private static int client;
  private Properties dbProps;
  private Vector drivers;
  
  public DBConnectionManager() {
  init();
  }
  
  public synchronized static DBConnectionManager getInstance(){
  if(instance==null){
  instance=new DBConnectionManager();
  }
  client++;
  return(instance);
  } //create an instance of connection manager. if exits ,just returen the instance
  
  void init(){
  drivers=new Vector();
  InputStream is=this.getClass().getResourceAsStream("../resource/Res.properties");
  try{
  dbProps=new Properties();
  dbProps.load(is);
  }catch(Exception ex){
  System.out.println("Miss Resource File "+ex.getMessage());
  }
  loadDriver();
  createPool();
  } //using Properties.load() method to locate outter properties file
  
  public void loadDriver(){
  String driverClasses=dbProps.getProperty("dbDriver");
  StringTokenizer st =new StringTokenizer(driverClasses);
  while(st.hasMoreElements()){
  String driverClassName=st.nextToken().trim();
  try{
  Driver driver=(Driver)Class.forName(driverClassName).newInstance();
  DriverManager.registerDriver(driver);
  drivers.addElement(driver);
  }catch(Exception ex){
  ex.printStackTrace();
  }
  }
  } //parse the file, load mutil driver class in
  
  public void createPool(){
  String userName=dbProps.getProperty("dbUserName");
  String passWord=dbProps.getProperty("dbPassword");
  String url=dbProps.getProperty("connectionURL");
  int maxConn;
  try{
  maxConn=Integer.valueOf(dbProps.getProperty("maxConnection","0")).intValue();
  }catch(NumberFormatException ex){
  maxConn=0;
  }
  pool=new DBConnectionPool(userName,password,url,maxConn);
  } //parse the file, load username,password,url and maxconnection in
  
  public synchronized int getClientCount(){
  return(client);
  }
  
  public Connection getDBConnection(){
  if(pool != null){
  return(pool.getDBConnection());
  }
  return(null);
  }//act as facade
  
  public Connection getDBConnection(long timeout){
  if(pool != null){
  return(pool.getDBConnection(timeout));
  }
  return(null);
  }//act as facade
  
  public void freeDBConnection(Connection conn){
  if(pool != null){
  pool.freeDBConnection(conn);
  }
  }//act as facade
  
  public void realse(){
  if(this.client != 0){
  return;
  }
  if(pool != null){
  pool.release();
  Enumeration enum=drivers.elements();
  while(enum.hasMoreElements()){
  Driver driver=(Driver)enum.nextElement();
  try{
  DriverManager.deregisterDriver(driver);
  }catch(Exception ex){
  System.out.println("Can not deregister driver "+driver.getClass().getName());
  }
  }
  }
  }//act as facade then de register driver
  
  }
  
  
  ________________________________________
  
  DBConnectionPool.java
  
  package com.coa.cim.database;
  
  /**
  *



發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 东安县| 宝鸡市| 丰台区| 鸡泽县| 阿尔山市| 兴国县| 潜山县| 阳信县| 河西区| 津市市| 鄯善县| 奎屯市| 永清县| 仪陇县| 郑州市| 沈阳市| 定远县| 澄城县| 河南省| 贵德县| 吉安市| 嘉禾县| 白银市| 当雄县| 天津市| 天气| 屏南县| 剑川县| 革吉县| 文昌市| 潍坊市| 怀来县| 元阳县| 余干县| 兴海县| 磐石市| 汝城县| 南宁市| 综艺| 嵩明县| 库尔勒市|