コード例 #1
0
  public static Connection connectWithC3p0() {
    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
    } catch (ClassNotFoundException cnfe) {
      System.err.println("Error: " + cnfe.getMessage());
    } catch (InstantiationException ie) {
      System.err.println("Error: " + ie.getMessage());
    } catch (IllegalAccessException iae) {
      System.err.println("Error: " + iae.getMessage());
    }

    ComboPooledDataSource cpds = getC3p0();

    try {
      if (con != null && !con.isClosed()) {
        con.close();
        con = null;
      }
      con = cpds.getConnection();
    } catch (SQLException ex) {
      ex.printStackTrace();
    }

    System.out.println("Returning c3p0 Connection " + con);
    return con;
  }
コード例 #2
0
  public static Connection connect() throws SQLException {
    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
    } catch (ClassNotFoundException cnfe) {
      System.err.println("Error: " + cnfe.getMessage());
    } catch (InstantiationException ie) {
      System.err.println("Error: " + ie.getMessage());
    } catch (IllegalAccessException iae) {
      System.err.println("Error: " + iae.getMessage());
    }

    con = DriverManager.getConnection(urlHC, userHC, passwordHC);

    return con;
  }
コード例 #3
0
  public static Connection connectWithHikari() throws SQLException {
    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
    } catch (ClassNotFoundException cnfe) {
      System.err.println("Error: " + cnfe.getMessage());
    } catch (InstantiationException ie) {
      System.err.println("Error: " + ie.getMessage());
    } catch (IllegalAccessException iae) {
      System.err.println("Error: " + iae.getMessage());
    }

    HikariDataSource ds = getHikari();
    if (con != null && !con.isClosed()) {
      con.close();
      con = null;
    }
    con = ds.getConnection();

    System.out.println("Returning Hikari Connection " + con);
    return con;
  }