List of usage examples for java.sql Connection commit
void commit() throws SQLException;
Connection
object. From source file:com.cloudera.sqoop.manager.MySQLCompatTest.java
@Override protected void dropTableIfExists(String table) throws SQLException { Connection conn = getManager().getConnection(); PreparedStatement statement = conn.prepareStatement("DROP TABLE IF EXISTS " + table, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); try {// www . j ava 2 s . com statement.executeUpdate(); conn.commit(); } finally { statement.close(); } }
From source file:com.mnt.base.das.DBFactory.java
public void endTransaction() { TransactionOwner to = toHolder.get(); if (to.decressDeep()) { Connection conn = to.connection; try {/*from www .ja v a2 s . c o m*/ conn.commit(); } catch (SQLException e) { log.error("Fail to commit the transaction, auto rollback.", e); try { conn.rollback(); } catch (SQLException e1) { log.error("Fail to rollback the transaction.", e1); throw new RuntimeException("End transaction error: fail to rollback the transaction.", e1); } } try { conn.setAutoCommit(true); } catch (SQLException e) { log.error("fail to set connection auto commit as true after the transacation.", e); throw new RuntimeException("end transaction error: fail to set connection auto commit as true.", e); } close(conn); toHolder.remove(); } }
From source file:com.csc.fsg.life.dao.bo.AbstractBusinessObjectHandler.java
/** Called to handle a command. //from ww w. ja v a 2 s.c o m Wraps the {@link #handle(AbstractBusinessObject, BusinessObjectCommand, Connection)} method by creating a connection and ensuring the connection is closed. @param dataSource the dataSource. @throws BusinessObjectException If there is a business error with the command. @throws SQLException If there is an I/O error with the command. **/ public void handle(DataSource dataSource) throws BusinessObjectException, SQLException { Connection conn = null; try { conn = dataSource.getConnection(); // turn auto-commit off conn.setAutoCommit(false); // call the concrete classes handle method handle(bo, command, conn); // since we are successful, commit the transaction conn.commit(); } catch (SQLException e) { if (conn != null) conn.rollback(); throw new SQLException(exceptionHandler.getReadableMessage(e)); } catch (BusinessObjectException e) { if (conn != null) conn.rollback(); throw new BusinessObjectException(exceptionHandler.getReadableMessage(e)); } catch (Exception e) { if (conn != null) conn.rollback(); throw new BusinessObjectException(exceptionHandler.getReadableMessage(e)); } finally { try { if (conn != null) conn.close(); } catch (Exception cme) { logger.error("Connection close exception: " + cme.getMessage()); } } }
From source file:mx.com.pixup.portal.dao.ArchivoBaseParserDaoJdbc.java
public void parserXML() { try {/*from w ww .j a v a2 s.c o m*/ //variables BD String sql = "INSERT INTO LATABLA VALUES (?)"; PreparedStatement preparedStatement; Connection connection = dataSource.getConnection(); connection.setAutoCommit(false); //se obtiene elemento raiz //elementos 2do nivel //construye parametros de la query //preparedStatement = connection.prepareStatement(sql); // preparedStatement.setInt(1, valor); // preparedStatement.execute(); connection.commit(); } catch (Exception e) { //*** se quit el return porque el mtodo es void System.out.println(e.getMessage()); } }
From source file:edu.caltechUcla.sselCassel.projects.jMarkets.server.data.DBConnector.java
/** Commit the current database transaction */ public void commit(Connection conn) throws SQLException { try {/* w w w . jav a2s . com*/ conn.commit(); conn.setAutoCommit(true); } catch (SQLException e) { throw e; } }
From source file:edu.ucsb.cs.eager.dao.EagerDependencyMgtDAO.java
public boolean recordDependencies(ApplicationInfo app) throws EagerException { Connection conn = null; try {//from w w w . ja va 2s .c om conn = APIMgtDBUtil.getConnection(); deleteExistingDependencies(conn, app); saveDependencies(conn, app); conn.commit(); return true; } catch (SQLException e) { handleException("Error while recording API dependency", e); return false; } finally { APIMgtDBUtil.closeAllConnections(null, conn, null); } }
From source file:com.taobao.tddl.jdbc.group.integration.TransactionTest.java
@Test public void springTest() throws Exception { Connection conn = ds.getConnection(); conn.setAutoCommit(false);// ww w. ja v a 2s . co m // Statementcrud Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select f1,f2 from crud"); assertEquals(stmt.executeUpdate("insert into crud(f1,f2) values(10,'str')"), 1); assertEquals(stmt.executeUpdate("insert into crud(f1,f2) values(10,'str')"), 1); conn.commit(); conn.setAutoCommit(true); rs = stmt.executeQuery("select f1,f2 from crud"); rs.next(); assertEquals(rs.getInt(1), 10); assertEquals(rs.getString(2), "str"); rs.close(); assertEquals(stmt.executeUpdate("delete from crud"), 2); stmt.close(); conn.close(); }
From source file:com.agiletec.aps.system.services.pagemodel.PageModelDAO.java
@Override public void deleteModel(String code) { Connection conn = null; PreparedStatement stat = null; try {// w w w . j av a 2 s .co m conn = this.getConnection(); conn.setAutoCommit(false); stat = conn.prepareStatement(DELETE_PAGEMODEL); stat.setString(1, code); stat.executeUpdate(); conn.commit(); } catch (Throwable t) { this.executeRollback(conn); _logger.error("Error while deleting a model", t); throw new RuntimeException("Error while deleting a model", t); } finally { this.closeDaoResources(null, stat, conn); } }
From source file:de.unidue.inf.is.ezdl.dlservices.repository.store.repositories.DBRepository.java
@Override public void removeDocument(String oid) { Connection con = null; PreparedStatement st = null;//from ww w. j a va2s. c om try { con = provider.connection(); st = con.prepareStatement(REMOVE); st.setString(1, databaseIdForOid(oid)); st.execute(); con.commit(); } catch (SQLException e) { rollback(con); getLogger().error("Error removing " + databaseIdForOid(oid), e); } finally { ClosingUtils.close(st); ClosingUtils.close(con); } }
From source file:com.cloudera.sqoop.testutil.HsqldbTestServer.java
/** * Delete any existing tables./*from ww w . j a va2s. c om*/ */ public void dropExistingSchema() throws SQLException { ConnManager mgr = getManager(); String[] tables = mgr.listTables(); if (null != tables) { Connection conn = mgr.getConnection(); for (String table : tables) { Statement s = conn.createStatement(); try { s.executeUpdate("DROP TABLE " + table); conn.commit(); } finally { s.close(); } } } }