List of usage examples for java.sql Connection rollback
void rollback() throws SQLException;
Connection
object. From source file:org.apache.hadoop.hive.jdbc.storagehandler.JdbcRecordWriter.java
@Override public void close(boolean abort) throws IOException { if (abort) {/*from ww w.ja v a2 s . co m*/ Connection conn = delegate.getConnection(); try { conn.rollback(); } catch (SQLException ex) { LOG.warn(StringUtils.stringifyException(ex)); } finally { try { conn.close(); } catch (SQLException ex) { throw new IOException(ex.getMessage()); } } } else { delegate.close(null); } }
From source file:dk.netarkivet.common.utils.DBUtils.java
/** * Method to perform a rollback of complex DB updates. If no commit has * been performed, this will undo the entire transaction, otherwise * nothing will happen. If autoCommit is true then no action is taken. * This method should be called in a finally block with * no DB updates after the last commit./*ww w. j a va 2 s . c om*/ * Thus exceptions while closing are ignored, but logged as warnings. * * NB: the provided connection is not closed. * * @param c the db-connection * @param action The action going on, before calling this method * @param o The Object being acted upon by this action */ public static void rollbackIfNeeded(Connection c, String action, Object o) { ArgumentNotValid.checkNotNull(c, "Connection c"); try { if (!c.getAutoCommit()) { c.rollback(); c.setAutoCommit(true); } } catch (SQLException e) { log.warn("SQL error doing rollback after " + action + " " + o + "\n" + ExceptionUtils.getSQLExceptionCause(e), e); // Can't throw here, we want the real exception } }
From source file:com.ibm.research.rdf.store.runtime.service.sql.UpdateHelper.java
private static String executeCall(Connection conn, String sql, int retPid, Object... params) { CallableStatement stmt = null; String ret = null;//from w ww. jav a 2 s . co m try { conn.setAutoCommit(false); } catch (SQLException ex) { log.error(ex); ex.printStackTrace(); System.out.println(ex.getLocalizedMessage()); return ret; } try { stmt = conn.prepareCall(sql); int i = 1; for (Object o : params) { stmt.setObject(i, o); i++; } stmt.registerOutParameter(retPid, Types.VARCHAR); stmt.execute(); ret = stmt.getString(retPid); conn.commit(); } catch (SQLException e) { // log.error(e); // e.printStackTrace(); // System.out.println(e.getLocalizedMessage()); ret = null; try { conn.rollback(); } catch (SQLException e1) { // TODO Auto-generated catch block log.error(e1); e1.printStackTrace(); System.out.println(e1.getLocalizedMessage()); ret = null; } } finally { closeSQLObjects(stmt, null); } try { conn.setAutoCommit(true); } catch (SQLException ex) { log.error(ex); ex.printStackTrace(); System.out.println(ex.getLocalizedMessage()); ret = null; } return ret; }
From source file:org.alinous.plugin.mysql.MySQLConnectionFactory.java
@Override public void passivateObject(Object arg0) throws Exception { Connection con = (Connection) arg0; if (!con.getAutoCommit()) { con.rollback(); con.setAutoCommit(true);//from ww w. j av a 2 s . co m } //AlinousDebug.debugOut("*************About passivateObject(arg0);"); super.passivateObject(arg0); }
From source file:cn.edu.seu.cose.jellyjolly.model.dao.jdbc.mysql.MysqlConnectionFactory.java
@Override public void rollbackConnection(Connection connection) throws JdbcDataAccessException { try {/*from ww w. j a v a 2 s .c om*/ if (connection != null) { connection.rollback(); } } catch (SQLException ex) { throw new JdbcDataAccessException(ex); } }
From source file:com.viettel.logistic.wms.service.SerialInventoryServiceImpl.java
private void rollback(Session session, Transaction transaction, Connection con) { try {/*w ww. j a v a2 s . c om*/ if (con != null) { con.rollback(); } if (transaction != null) { transaction.rollback(); } if (con != null && !con.isClosed()) { con.close(); } } catch (SQLException ex) { Logger.getLogger(StockImportServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } if (session != null && session.isOpen()) { session.close(); } }
From source file:hermes.store.jdbc.JDBCConnectionPool.java
public boolean beforeCheckin(Connection connection) { try {/*from ww w. j a v a 2 s.c o m*/ if (connection.isClosed()) { return false; } else { if (!connection.getAutoCommit()) { connection.rollback(); } } } catch (SQLException ex) { log.warn("beforeCheckin failed:" + ex.getMessage(), ex); return false; } return true; }
From source file:com.reydentx.core.client.MySQLClient.java
public void rollback(Connection client) { try {//from ww w . j ava 2s . c o m client.rollback(); } catch (SQLException ex) { _logger.error(ex.getMessage(), ex); } }
From source file:ccc.cli.StringToDecConverter.java
private void commit(final Connection con) { try {/*from w w w . j a va2 s . c om*/ con.commit(); } catch (final SQLException e) { LOG.fatal("Error committing changes", e); try { LOG.error("Rolling back connection"); con.rollback(); LOG.info("Rolled back connection successfully"); } catch (final SQLException e1) { LOG.error("Failed to rollback connection"); } } }
From source file:com.devwebsphere.jdbc.loader.JDBCTxCallback.java
/** * This is called when a WXS transaction needs to rollback. If a Data instance was created for the transaction * then roll it back and clean up/*w ww .j a va 2s. c om*/ */ public void rollback(TxID tx) throws TransactionCallbackException { if (tx.getSession().getObjectGrid().getObjectGridType() == ObjectGrid.SERVER) { try { Connection c = (Connection) tx.getSlot(dataSlot); if (c != null) { c.rollback(); c.close(); tx.putSlot(dataSlot, null); } } catch (SQLException e) { throw new TransactionCallbackException(e); } } }