Code example for Connection

Methods: closegetAutoCommit

0
    if (connection != null) {
      resetAutoCommit(); 
      if (log.isDebugEnabled()) {
        log.debug("Closing JDBC Connection [" + connection + "]");
      } 
      connection.close();
    } 
  } 
 
  protected void setDesiredAutoCommit(boolean desiredAutoCommit) {
    try { 
      if (connection.getAutoCommit() != desiredAutoCommit) {
        if (log.isDebugEnabled()) {
          log.debug("Setting autocommit to " + desiredAutoCommit + " on JDBC Connection [" + connection + "]");
        } 
        connection.setAutoCommit(desiredAutoCommit);
      } 
    } catch (SQLException e) {
      // Only a very poorly implemented driver would fail here, 
      // and there's not much we can do about that. 
      throw new TransactionException("Error configuring AutoCommit.  " 
          + "Your driver may not support getAutoCommit() or setAutoCommit(). " 
          + "Requested setting: " + desiredAutoCommit + ".  Cause: " + e, e);
    } 
  } 
 
  protected void resetAutoCommit() { 
    try { 
      if (!connection.getAutoCommit()) {
        // MyBatis does not call commit/rollback on a connection if just selects were performed. 
        // Some databases start transactions with select statements 
        // and they mandate a commit/rollback before closing the connection. 
        // A workaround is setting the autocommit to true before closing the connection. 
        // Sybase throws an exception here. 
Stop searching for code, let great code find you!  Add Codota to your java IDE