Beispiel #1
0
  /**
   * 根据指定属性创建连接池实例.
   *
   * @param props 连接池属性
   * @throws Exception
   */
  private void createPools() throws Exception {
    DOMParse d1 = new DOMParse("dataSources.xml");
    Vector sv = d1.addDataSourceVector();
    Iterator ite = sv.iterator();
    while (ite.hasNext()) {
      DataSource db = (DataSource) ite.next();

      DBConnectionPool pool =
          new DBConnectionPool(
              db.getId(), db.getUrl(), db.getUsername(), db.getPassword(), db.getMaxconn());

      pools.put(new Integer(db.getId()), pool);
      // log("成功创建连接池" + poolName);
    }
  }
Beispiel #2
0
  /**
   * 装载和注册所有JDBC驱动程序
   *
   * @throws Exception
   */
  private void loadDrivers() throws Exception {
    DOMParse d1 = new DOMParse("dataSources.xml");
    Vector sv = d1.addDataSourceVector();
    Iterator ite = sv.iterator();
    while (ite.hasNext()) {
      DataSource db = (DataSource) ite.next();
      try {
        Driver driver = (Driver) Class.forName(db.getDriver_class()).newInstance();
        DriverManager.registerDriver(driver);
        drivers.addElement(db.getDriver_class());
        System.out.println(db.getDriver_class());

      } catch (Exception e) {
        System.out.println("无法注册JDBC驱动程序: " + db.getDriver_class() + ", 错误: " + e);
      }
    }
  }