Example usage for org.springframework.jdbc.core JdbcOperations update

List of usage examples for org.springframework.jdbc.core JdbcOperations update

Introduction

In this page you can find the example usage for org.springframework.jdbc.core JdbcOperations update.

Prototype

int update(String sql, @Nullable Object... args) throws DataAccessException;

Source Link

Document

Issue a single SQL update operation (such as an insert, update or delete statement) via a prepared statement, binding the given arguments.

Usage

From source file:com.nortal.petit.core.dialect.PostgreSqlDialect.java

@SuppressWarnings("unchecked")
@Override//  www. jav a2 s  .com
public <B> B insertReturningId(JdbcOperations jdbcOperations, final String sql, String idColumn,
        final Object... params) {
    KeyHolder keyHolder = new GeneratedKeyHolder();
    jdbcOperations.update(new PreparedStatementCreator() {
        @Override
        public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
            PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
            Object[] queryParams = params.length == 1 && params[0] instanceof Object[] ? (Object[]) params[0]
                    : params;
            ArgPreparedStatementSetter.setValues(ps, queryParams, 1);
            return ps;
        }
    }, keyHolder);
    return (B) keyHolder.getKeys().get(idColumn);
}

From source file:org.danann.cernunnos.sql.UpsertTask.java

/**
 * Executes the insert and returns the affected row count
 * //  ww w .  jav  a2s  .  com
 * Moved to its own method to reduce possibility for variable name confusion
 */
protected int doInsert(JdbcOperations jdbcOperations, TaskRequest req, TaskResponse res) {
    //Setup the insert parameters and setter
    final List<Phrase> parametersInUse = insert_parameters != null ? insert_parameters : parameters;
    final PreparedStatementSetter preparedStatementSetter = new PhraseParameterPreparedStatementSetter(
            parametersInUse, req, res);

    //Get the insert sql and execute the insert
    final String fInsertSql = (String) insert_sql.evaluate(req, res);
    return jdbcOperations.update(fInsertSql, preparedStatementSetter);
}

From source file:org.danann.cernunnos.sql.UpsertTask.java

/**
 * Executes the update and returns the affected row count
 * /*  w  ww.j  a  va2 s  .  c  om*/
 * Moved to its own method to reduce possibility for variable name confusion
 */
protected int doUpdate(JdbcOperations jdbcOperations, TaskRequest req, TaskResponse res) {
    //Setup the update parameters and setter
    final List<Phrase> parametersInUse = update_parameters != null ? update_parameters : parameters;
    final PreparedStatementSetter preparedStatementSetter = new PhraseParameterPreparedStatementSetter(
            parametersInUse, req, res);

    //Get the update sql and execute the update.
    final String fUpdateSql = (String) update_sql.evaluate(req, res);
    return jdbcOperations.update(fUpdateSql, preparedStatementSetter);
}