List of usage examples for java.sql Connection commit
void commit() throws SQLException;
Connection
object. From source file:com.vertica.hadoop.AbstractVerticaOutputCommitter.java
/** * Commits and closes the connection if the connection is non-null and open. * @throws IOException if either isClosed or commit fails. *//*from w ww .j av a 2 s. c om*/ protected final void sqlCommit(Connection connection) throws IOException { try { if (connection == null || connection.isClosed()) { throw new IOException("Trying to commit a connection that is null or closed: " + connection); } } catch (SQLException e) { throw new IOException("Exception calling isClosed on connection", e); } try { connection.commit(); } catch (SQLException e) { throw new IOException("Exception committing connection", e); } finally { sqlClose(connection); } }
From source file:com.fileanalyzer.dao.impl.FilesDAOImpl.java
@Override public void delete(Files fileInDb) { Connection con = null; Statement statement = null;/* w w w. ja v a 2 s. co m*/ try { con = DBConnector.getConnection(); con.setAutoCommit(false); statement = con.createStatement(); statement.execute("delete from " + Files.FilesFieldsKey.TABLE + " where id=" + fileInDb.getId()); con.commit(); } catch (SQLException e) { handleException(e, con); } finally { if (statement != null) { try { statement.close(); } catch (SQLException ex) { log.error(ex); } } try { con.setAutoCommit(true); } catch (SQLException ex) { log.error("setAutoCommit(true)", ex); } if (con != null) { try { con.close(); } catch (SQLException ex) { log.error(ex); } } } }
From source file:dbcount.DbCountInitializeJob.java
private void dropTables(final Connection conn, final boolean useView) { final String dropAccess = "DROP TABLE Access"; final String dropPageview = "DROP TABLE Pageview"; try {/*from w w w. ja va 2 s.com*/ Statement st = conn.createStatement(); st.executeUpdate(dropAccess); if (!useView) { st.executeUpdate(dropPageview); } conn.commit(); st.close(); } catch (SQLException ex) {// ignore try { conn.rollback(); } catch (SQLException e) { ; } } }
From source file:gridool.db.partitioning.monetdb.MonetDBInvokeCopyIntoOperation.java
@Override public Serializable execute() throws SQLException { final Connection conn; try {//from w w w. j a v a 2 s . c o m conn = getConnection(); } catch (ClassNotFoundException e) { LOG.error(e); throw new SQLException(e.getMessage()); } final File loadFile = prepareLoadFile(tableName); final String query = complementCopyIntoQuery(copyIntoQuery, loadFile); try { JDBCUtils.update(conn, query); conn.commit(); } catch (SQLException e) { LOG.error("rollback a transaction", e); conn.rollback(); throw e; } finally { try { conn.close(); } catch (SQLException e) { LOG.debug(e); } if (!loadFile.delete()) { LOG.warn("Could not remove a tempolary file: " + loadFile.getAbsolutePath()); } } return Boolean.TRUE; }
From source file:org.tradex.jdbc.JDBCHelper.java
/** * Executes the passed SQL as an update and returns the result code * @param sql The update SQL//from ww w. ja va 2 s .c o m * @return the result code */ public int executeUpdate(CharSequence sql) { Connection conn = null; PreparedStatement ps = null; try { conn = ds.getConnection(); ps = conn.prepareStatement(sql.toString()); conn.commit(); return ps.executeUpdate(); } catch (Exception e) { throw new RuntimeException("Update for [" + sql + "] failed", e); } finally { try { ps.close(); } catch (Exception e) { } try { conn.close(); } catch (Exception e) { } } }
From source file:org.brixcms.rmiserver.boot.Bootstrapper.java
/** * @param sf/*from w w w .j av a 2s .c o m*/ */ private void bootstrapSchema() { Connection con = null; try { con = datasource.getConnection(); Dialect dialect = Dialect.getDialect(configuration.getProperties()); String[] schema = configuration.generateSchemaCreationScript(dialect); for (String stmt : schema) { Statement st = con.createStatement(); st.executeUpdate(stmt); st.close(); } con.commit(); } catch (SQLException e1) { if (con != null) { try { con.rollback(); } catch (SQLException e2) { try { con.close(); } catch (SQLException e3) { } } } } }
From source file:de.unidue.inf.is.ezdl.dlservices.repository.store.repositories.DBRepository.java
@Override public int getRepositorySize() { int count = 0; Connection con = null; PreparedStatement st = null;/*from w w w. ja v a 2s. co m*/ ResultSet res = null; try { con = provider.connection(); st = con.prepareStatement(COUNT); res = st.executeQuery(); if (res.next()) { count = res.getInt(1); } con.commit(); } catch (SQLException e) { rollback(con); getLogger().error("Error getting count", e); } finally { ClosingUtils.close(res); ClosingUtils.close(st); ClosingUtils.close(con); } return count; }
From source file:com.splicemachine.derby.test.framework.SpliceFunctionWatcher.java
@Override protected void starting(Description description) { LOG.trace("Starting"); Connection connection = null; Statement statement = null;/*from w w w.j a v a2 s .com*/ ResultSet rs = null; try { connection = (userName == null) ? SpliceNetConnection.getConnection() : SpliceNetConnection.getConnectionAs(userName, password); rs = connection.getMetaData().getTables(null, schemaName, functionName, null); if (rs.next()) { executeDrop(schemaName, functionName); } connection.commit(); statement = connection.createStatement(); statement.execute(CREATE_FUNCTION + schemaName + "." + functionName + " " + createString); connection.commit(); } catch (Exception e) { LOG.error("Create function statement is invalid "); e.printStackTrace(); throw new RuntimeException(e); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(statement); DbUtils.commitAndCloseQuietly(connection); } super.starting(description); }
From source file:com.netflix.metacat.usermetadata.mysql.MySqlTagService.java
private void remove(final QualifiedName name, final Set<String> tags, final boolean updateUserMetadata) { try {/*from w ww . j av a 2 s.com*/ final Connection conn = getDataSource().getConnection(); try { remove(conn, name, tags, updateUserMetadata); conn.commit(); } catch (SQLException e) { conn.rollback(); throw e; } finally { conn.close(); } } catch (SQLException e) { final String message = String.format("Failed to remove tags for name %s", name); log.error(message, e); throw new UserMetadataServiceException(message, e); } }
From source file:com.splicemachine.derby.test.framework.SpliceViewWatcher.java
@Override public void starting(Description description) { LOG.trace("Starting"); Connection connection = null; Statement statement = null;/*from www .j a v a 2 s . co m*/ ResultSet rs = null; try { connection = userName == null ? SpliceNetConnection.getConnection() : SpliceNetConnection.getConnectionAs(userName, password); rs = connection.getMetaData().getTables(null, schemaName, viewName, null); if (rs.next()) { executeDrop(schemaName, viewName); } connection.commit(); statement = connection.createStatement(); statement.execute(CREATE_VIEW + schemaName + "." + viewName + " " + createString); connection.commit(); } catch (Exception e) { LOG.error("Create view statement is invalid "); e.printStackTrace(System.err); throw new RuntimeException(e); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(statement); DbUtils.commitAndCloseQuietly(connection); } super.starting(description); }