⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connectionpool.java~28~

📁 一个很不错的电子商务后台管理系统 这是一个电子商务网站的后台管理系统 要运行此系统必须具备以下条件 1.首先要把SNSQL文本中的SQL脚本确保在SQL Server中执行 2.包Se
💻 JAVA~28~
字号:
package xian.bin.db;
import java.sql.*;
import java.util.*;
public class ConnectionPool {
  public static ConnectionPool pcon = new ConnectionPool();
  private String driver;
  private String url;
  private Connection con;
  private int size;
  private ArrayList arr=new ArrayList();
  private ConnectionPool(){
    try{
      this.iniait();
    }
    catch(Exception e){
      e.printStackTrace();
    }
  }
  public static ConnectionPool getConnectionPool(){
    if(pcon==null){
      pcon = new ConnectionPool();
    }
    return pcon;
  }

  //初始化连接池
  public void iniait()throws Exception{
    try{
      System.out.println("正要加载驱动!!!!");
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      for(int i=0;i<5;i++){
        con=DriverManager.getConnection("jdbc:odbc:product","","");
        PoolConnection pcon=new PoolConnection(con);
        arr.add(pcon);
      }
      System.out.println("初始化连接池");
    }
    catch(Exception e){
      e.printStackTrace();
    }
  }

  //得到一个连接
  public synchronized Connection getConnection()throws Exception{
    Iterator its=arr.iterator();
    PoolConnection con=null;
    while(its.hasNext()){
       con=(PoolConnection)its.next();
    }
    System.out.println("得到一个连接");

    return con.getCon();
  }

  public String getDriver() {
    return driver;
  }
  public void setDriver(String driver) {
    this.driver = driver;
  }
  public String getUrl() {
    return url;
  }
  public void setUrl(String url) {
    this.url = url;
  }
  public int getSize() {
    return size;
  }
  public void setSize(int size) {
    this.size = size;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -