public interface JdbcUpdate extends AutoCloseable
This API uses the builder pattern to allow an update operation to be easily configured and executed, using a fluent expression.
An instance of this type is created using the
update method on the JdbcOperations
interface. The update operation must be configured with a statement to
execute via the using method.
Additionally, the update operation can be configured for single execution
(default) or repeated execution. When an update is configured for repeated
execution (using repeatedly()), the underlying statement and
connection objects remain open after the execute(Parameter...),
method is invoked, allowing the update operation to be executed again with
different parameter values. An update operation that is configured
for repeated execution must be closed when it is no longer needed, by
invoking the close() method explicitly or by enclosing it in a
try-with-resources construct.
After the update operation has been configured, it can be executed using
the execute(Parameter...) method.
Examples:
Updating many rows with a single statement execution:
int count = sqlTemplate.update()
.using("DELETE FROM person WHERE status = ?")
.execute(Parameter.with("INACTIVE");
Repeatedly executing the same update operation with different parameters:
try (JdbcUpdate updater = sqlTemplate.update()
.using("UPDATE person SET age = age + 1 WHERE id = ?")
.repeatedly()) {
updater.execute(Parameter.with(1L));
updater.execute(Parameter.with(4L));
}
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the JDBC resources associated with this update.
|
int |
execute(Parameter... parameters)
Executes this update.
|
JdbcUpdate |
repeatedly()
Configures this update for repeated execution.
|
JdbcUpdate |
using(SQLSource source)
Configures this update to execute the given SQL statement.
|
JdbcUpdate |
using(String sql)
Configures this update to execute the given SQL statement.
|
JdbcUpdate using(String sql)
sql - the SQL statement to executeJdbcUpdate using(SQLSource source)
source - for the SQL statement to executeJdbcUpdate repeatedly()
An update that is configured as repeatable must be explicitly closed by
the caller using close() when no longer needed.
int execute(Parameter... parameters)
parameters - values for placeholders in the SQL statementvoid close()
After an update is closed, its execute(Parameter...) method may
not be subsequently invoked.
close in interface AutoCloseableCopyright © 2014–2015 Carl Harris, Jr. All rights reserved.