/** * {@inheritDoc} */ @Override public boolean delete(Customer customer) throws Exception { try (Connection connection = getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM CUSTOMERS WHERE ID = ?")) { statement.setInt(1, customer.getId()); return statement.executeUpdate() > 0; } catch (SQLException ex) { throw new CustomException(ex.getMessage(), ex); } } }
/** * {@inheritDoc} */ @Override public boolean update(Customer customer) throws Exception { try (Connection connection = getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE CUSTOMERS SET FNAME = ?, LNAME = ? WHERE ID = ?")) { statement.setString(1, customer.getFirstName()); statement.setString(2, customer.getLastName()); statement.setInt(3, customer.getId()); return statement.executeUpdate() > 0; } catch (SQLException ex) { throw new CustomException(ex.getMessage(), ex); } }
public void create(Entity entity) throws SQLException { Connection connection = null; PreparedStatement statement = null; try { connection = dataSource.getConnection(); statement = connection.prepareStatement(SQL_CREATE); statement.setSomeObject(1, entity.getSomeProperty()); // ... statement.executeUpdate(); } finally { if (statement != null) try { statement.close(); } catch (SQLException logOrIgnore) {} if (connection != null) try { connection.close(); } catch (SQLException logOrIgnore) {} } }
public int deleteFiredTriggers(Connection conn, String theInstanceId) throws SQLException { PreparedStatement ps = null; try { ps = conn.prepareStatement(rtp(DELETE_INSTANCES_FIRED_TRIGGERS)); ps.setString(1, theInstanceId); return ps.executeUpdate(); } finally { closeStatement(ps); } }
void f2() throws SQLException { PreparedStatement insertFieldAudit = null; try { insertFieldAudit = getConnection().prepareStatement(INSERT_FIELD_AUDIT); insertFieldAudit.executeUpdate(); insertFieldAudit = getConnection().prepareStatement(INSERT_FIELD_AUDIT); insertFieldAudit.executeUpdate(); } finally { insertFieldAudit.close(); } }
public int insert(String sql, Object... params) throws SQLException { try (PreparedStatement query = getConnection().prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { resolveParameters(query, params); query.executeUpdate(); ResultSet rs = query.getGeneratedKeys(); if (rs.next()) { return rs.getInt(1); } } return -1; } }
public insertUser(String name, String email) { Connection conn = null; PreparedStatement stmt = null; try { conn = setupTheDatabaseConnectionSomehow(); stmt = conn.prepareStatement("INSERT INTO person (name, email) values (?, ?)"); stmt.setString(1, name); stmt.setString(2, email); stmt.executeUpdate(); } finally { try { if (stmt != null) { stmt.close(); } } catch (Exception e) { // log this error } try { if (conn != null) { conn.close(); } } catch (Exception e) { // log this error } } }
public int deleteSchedulerState(Connection conn, String theInstanceId) throws SQLException { PreparedStatement ps = null; try { ps = conn.prepareStatement(rtp(DELETE_SCHEDULER_STATE)); ps.setString(1, theInstanceId); return ps.executeUpdate(); } finally { closeStatement(ps); } }
void f() throws SQLException { PreparedStatement insertFieldAudit = null; try { for (int i = 1; i <= 10; i++) { insertFieldAudit = getConnection().prepareStatement(INSERT_FIELD_AUDIT); insertFieldAudit.executeUpdate(); } } finally { insertFieldAudit.close(); } }
public void create(Entity entity) throws SQLException { Connection connection = null; PreparedStatement statement = null; try { connection = database.getConnection(); statement = connection.prepareStatement(SQL_CREATE); statement.setSomeObject(1, entity.getSomeProperty()); // ... statement.executeUpdate(); } finally { if (statement != null) try { statement.close(); } catch (SQLException logOrIgnore) {} if (connection != null) try { connection.close(); } catch (SQLException logOrIgnore) {} } }
@Override public void doDeleteOldMessages(TransactionContext c) throws SQLException, IOException { PreparedStatement s = null; try { LOG.debug("Executing SQL: " + this.statements.getDeleteOldMessagesStatementWithPriority()); s = c.getExclusiveConnection().prepareStatement(this.statements.getDeleteOldMessagesStatementWithPriority()); int priority = priorityIterator++%10; s.setInt(1, priority); s.setInt(2, priority); int i = s.executeUpdate(); LOG.debug("Deleted " + i + " old message(s) at priority: " + priority); } finally { close(s); } }
logger.debug("The following parameters are used for call " + getInsertString() + " with: " + values); getJdbcTemplate().update( con -> { PreparedStatement ps = prepareStatementForGeneratedKeys(con); setParameterValues(ps, values, getInsertTypes()); return ps; "The getGeneratedKeys feature is not supported by this database"); if (getGeneratedKeyNames().length < 1) { throw new InvalidDataAccessApiUsageException("Generated Key Name(s) not specified. " + "Using the generated keys features requires specifying the name(s) of the generated column(s)"); if (getGeneratedKeyNames().length > 1) { throw new InvalidDataAccessApiUsageException( "Current database only supports retrieving the key for a single column. There are " + getGeneratedKeyNames().length + " columns specified: " + Arrays.asList(getGeneratedKeyNames())); try { ps = con.prepareStatement(getInsertString()); setParameterValues(ps, values, getInsertTypes()); ps.executeUpdate();
static void perform(Connection cxn, long id, String selections, boolean isBlacklist) throws SQLException { try (PreparedStatement ps = cxn.prepareStatement("UPDATE pipelineselections SET selections = NULL, version = ?, filters = ? WHERE id = ?")) { ps.setInt(1, SCHEMA); ps.setString(2, asJson(selections, isBlacklist)); ps.setLong(3, id); ps.executeUpdate(); } }
public int deleteSchedulerState(Connection conn, String theInstanceId) throws SQLException { PreparedStatement ps = null; try { ps = conn.prepareStatement(rtp(DELETE_SCHEDULER_STATE)); ps.setString(1, theInstanceId); return ps.executeUpdate(); } finally { closeStatement(ps); } }
public int update(String sql, Object... args) throws SQLException { PreparedStatement ps = connection.prepareStatement(sql); try { setParameters(ps, args); return ps.executeUpdate(); } finally { try { ps.close(); } catch (SQLException e) { //ignore } } }
TransactionListener transactionListener = new CompositeTransactionListener( configuration.getTransactionListenerFactories()); try { Connection connection = configuration.getConnection(); StatementListener listener = configuration.getStatementListener(); if (query.insertType() == InsertType.SELECT) { statement = connection.prepareStatement(sql, Statement.NO_GENERATED_KEYS); } else { statement = prepare(sql, connection); transactionListener.beforeCommit(types); count = statement.executeUpdate(); connection.close(); MutableTuple tuple = new MutableTuple(1); tuple.set(0, NamedExpression.ofInteger("count"), count); return new CollectionResult<Tuple>(tuple); } else { ResultSet results = statement.getGeneratedKeys(); return new GeneratedKeyResult(configuration, selection, connection, results, count);
private void insertRowIntoTestTable() throws SQLException { try (Connection conn = connectionFactory.createConnection(); PreparedStatement stmnt = conn.prepareStatement(INSERT_SQL)) { stmnt.setInt(1, TEST_VALUE); stmnt.executeUpdate(); } }
static void perform(Connection cxn, long id, String filters) throws SQLException { try (PreparedStatement ps = cxn.prepareStatement("UPDATE pipelineselections SET version = ?, filters = ? WHERE id = ?")) { ps.setInt(1, SCHEMA); ps.setString(2, addStateIfNull(filters)); ps.setLong(3, id); ps.executeUpdate(); } }
public int deletePausedTriggerGroup(Connection conn, GroupMatcher<TriggerKey> matcher) throws SQLException { PreparedStatement ps = null; try { ps = conn.prepareStatement(rtp(DELETE_PAUSED_TRIGGER_GROUP)); ps.setString(1, toSqlLikeClause(matcher)); int rows = ps.executeUpdate(); return rows; } finally { closeStatement(ps); } }
@ExpectWarning("ODR_OPEN_DATABASE_RESOURCE") public static void test0(String url) throws Exception { Connection conn; PreparedStatement pstm = null; try { conn = DriverManager.getConnection(url); pstm = conn.prepareStatement("123"); pstm.executeUpdate(); } finally { if (pstm != null) pstm.close(); } }