Code example for Connection

Methods: isClosedrollbacksetAutoCommit

0
   */ 
  private boolean closeConnection(Connection conn) {
    if (conn == null)
      return false; 
    try { 
      conn.setAutoCommit(true);
      conn.close();
    } catch (Exception ex) {
      log4j.error("Error on closeConnection", ex);
      return false; 
    } 
    return true; 
  } 
 
  public Connection getTransactionConnection() throws NoConnectionAvailableException, SQLException {
    Connection conn = getNewConnection();
    if (conn == null)
      throw new NoConnectionAvailableException("Couldn´t get an available connection"); 
    conn.setAutoCommit(false);
    return conn;
  } 
 
  public void releaseCommitConnection(Connection conn) throws SQLException {
    if (conn == null)
      return; 
    conn.commit();
    closeConnection(conn);
  } 
 
  public void releaseRollbackConnection(Connection conn) throws SQLException {
    if (conn == null)
      return; 
    // prevent extra exception if the connection is already closed 
    // especially needed here because rollback occurs in case of 
    // application exceptions also. If the conn.isClosed and a rollback 
    // is done then the real app exception is hidden. 
    if (conn.isClosed()) {
      return; 
    } 
    conn.rollback();
    closeConnection(conn);
  } 
 
  public PreparedStatement getPreparedStatement(String SQLPreparedStatement) throws Exception {
    return getPreparedStatement(defaultPoolName, SQLPreparedStatement);