package stumng;

import java.sql.*;
import java.util.*;
import java.sql.Date;
import java.util.regex.*;

/*连接池管理类,可以管理多个数据库连接池*/
public class DBConnManager {
  //连接池名列表
  private Vector poolnames=new Vector();

  //驱动程序名列表
  private Vector drivernames=new Vector();

  //数据库标识列表
  private Vector dbids=new Vector();

  //用户名列表
  private Vector usernames=new Vector();

  //密码列表
  private Vector passwds=new Vector();

  //最大连接数列表
  private Vector maxconns=new Vector();

  //连接池队列
  private Hashtable connPools=new Hashtable();

  public DBConnManager() {
    //添加Access数据库的连接信息
    poolnames.addElement("Access");
    drivernames.addElement("sun.jdbc.odbc.JdbcOdbcDriver");
    dbids.addElement("jdbc:odbc:stuMngs");
    usernames.addElement("sa");
    passwds.addElement("sa");
    maxconns.addElement("300");

    //创建连接池
    createPools();
  }

  /*将连接返回给由指定的连接池*/
  public void releaseConnection(String name, Connection con) {
    DBConnPool pool=(DBConnPool) connPools.get(name);
    if (pool!=null)
      pool.releaseConnection(con);
  }

  /*得到一个指定连接池中的连接*/
  public Connection getConnection(String name) {
    DBConnPool pool=(DBConnPool) connPools.get(name);
    if (pool != null)
      return pool.getConnection();
    else return null;
  }

  /*往Access数据库中插入数据时，进行编码转换*
           public String ISOtoGBK(String iso) {
    String gb;
    try {
      if (iso.equals("")) {
        return "";
      }
      else {
        gb=new String(iso.getBytes("ISO-8859-1"),"GBK");
        return gb;
      }
    }
    catch (Exception e) {
      System.err.print("编码转换错误：" + e.getMessage());
      return "";
    }
           }

   *往Access数据库中取数据时，进行编码转换*
           public String GBKtoISO(String gb) {
    String iso;
    try {
      if (gb.equals("")) {
        return "";
      }
      else {
        iso=new String(gb.getBytes("GBK"), "ISO-8859-1");
        return iso;
      }
    }
    catch (Exception e) {
      System.err.print("编码转换错误：" + e.getMessage());
      return "";
    }
           }*/}
