请各位高手帮忙解决如何在jbuilderx中配置数据库连接池(谢谢!),(24分)

  • 主题发起人 主题发起人 laozheng
  • 开始时间 开始时间
L

laozheng

Unregistered / Unconfirmed
GUEST, unregistred user!
请各位高手帮忙解决如何在jbuilderx中配置数据库连接池(谢谢!),
 
我写的数据库连接池的连接BEAN
代码:
package pub;
import java.sql.*;
public class AccessDB {
  private Connection con;
  private Statement sttm;
  private String driver = "COM.ibm.db2.jdbc.app.Driver";
  private String dbURL = "jdbc:db2://172.23.72.109:50000/XZGD";
  private String login = "administrator";
  private String password = "syxx";
  
  public void setDriver(String sDriver) {
    if (sDriver != null) {
      driver = sDriver;
    }
  }
  
  public String getDriver() {
    return driver;
  }
  
  public void setDbURL(String sDbURL) {
    if (sDbURL != null) {
      dbURL = sDbURL;
    }
  }
  
  public String getDbURL() {
    return dbURL;
  }
  
  public void setLogin(String sLogin) {
    if (sLogin != null) {
      login = sLogin;
    }
  }
  
  public String getLogin() {
    return login;
  }
  
  public void setPassword(String sPassword) {
    if (sPassword != null) {
      password = sPassword;
    }
  }
  
  private String getPassword() {
    return password;
  }
  
  private void getConn() {
    try {
      Class.forName(driver);
      con = DriverManager.getConnection(dbURL, login, password);
      sttm = con.createStatement();
    }
    catch(ClassNotFoundException e) {
      System.out.println("ConnectionManager: driver unavailable");
      con = null;
    }
    catch(SQLException e) {
      System.out.println("ConnectionManager: driver not loaded");
      con = null;
    }
  }
  
  public Connection getConnection() {
    if (con == null) {
      getConn();
    }
    return con;
  }
  
  public void commit() throws SQLException {
    con.commit();
  }
  
  public void rollback() throws SQLException {
    con.rollback();
  }
  
  public void setAutoCommit(boolean autoCommit) throws SQLException {
    con.setAutoCommit(autoCommit);
  }
  
  public ResultSet executeQuery(String sql) throws SQLException {
    if (con == null || con.isClosed()) {
      getConn();
    }
    return sttm.executeQuery(sql);
  }
  
  public int executeUpdate(String sql) throws SQLException {
    if (con == null || con.isClosed()) {
      getConn();
    }
    return sttm.executeUpdate(sql);
  }
  
  public void close() {
    try {
      if (con != null || !con.isClosed()) {
        con.close();
      }
    }
    catch(SQLException e) {
      e.printStackTrace();
    }
  }
}
 
后退
顶部