This class provides a number of update methods,
analogous to the execute methods of query objects.
This class is concrete. Although it can be subclassed (for example to add a custom update method) it can easily be parameterized by setting SQL and declaring parameters.
Like all RdbmsOperation classes that ship with the Spring
Framework, SqlQuery instances are thread-safe after their
initialization is complete. That is, after they are constructed and configured
via their setter methods, they can be used safely from multiple threads.
SqlQuery
| Modifier and Type | Field and Description |
|---|---|
| private int | maxRowsAffected
Maximum number of rows the update may affect. |
| private int | requiredRowsAffected
An exact number of rows that must be affected. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | SqlUpdate(DataSource
the DataSource to use to obtain connections ds, String the SQL statement to execute sql)Constructs an update object with a given DataSource and SQL. |
| public | SqlUpdate(DataSource
the DataSource to use to obtain connections ds, String the SQL statement to execute sql, int[] the SQL types of the parameters, as defined in the
types)java.sql.Types classConstruct an update object with a given DataSource, SQL and anonymous parameters. |
| public | SqlUpdate(DataSource
the DataSource to use to obtain connections ds, String the SQL statement to execute sql, int[] the SQL types of the parameters, as defined in the
types, int java.sql.Types classthe maximum number of rows that may
be affected by the update maxRowsAffected)Construct an update object with a given DataSource, SQL, anonymous parameters and specifying the maximum number of rows that may be affected. |
| Modifier and Type | Method and Description |
|---|---|
| protected void | checkRowsAffected(int
the number of affected rows rowsAffected)Check the given number of affected rows against the specified maximum number or required number. |
| public void | setMaxRowsAffected(int
the maximum number of rows that can be affected by
this update without this class's update method considering it an error maxRowsAffected)Set the maximum number of rows that may be affected by this update. |
| public void | setRequiredRowsAffected(int
the exact number of rows that must be affected
by this update without this class's update method considering it an error requiredRowsAffected)Set the exact number of rows that must be affected by this update. |
| public int | |
| public int | |
| public int | |
| public int | |
| public int | |
| public int | |
| public int | |
| public int | |
| public int | |
| public int | Returns: the number of rows affected by the updatea Map of parameter name to parameter object,
matching named parameters specified in the SQL statement paramMap)Generic method to execute the update given named parameters. |
| public int | Returns: the number of rows affected by the updatea Map of parameter name to parameter object,
matching named parameters specified in the SQL statement paramMap, KeyHolder the KeyHolder that will hold the generated keys generatedKeyHolder)Method to execute the update given arguments and retrieve the generated keys using a KeyHolder. |
| maxRowsAffected | back to summary |
|---|---|
| private int maxRowsAffected Maximum number of rows the update may affect. If more are affected, an exception will be thrown. Ignored if 0. | |
| requiredRowsAffected | back to summary |
|---|---|
| private int requiredRowsAffected An exact number of rows that must be affected. Ignored if 0. | |
| SqlUpdate | back to summary |
|---|---|
| public SqlUpdate() Constructor to allow use as a JavaBean. DataSource and SQL must be supplied before compilation and use.
| |
| SqlUpdate | back to summary |
|---|---|
| public SqlUpdate(DataSource ds, String sql) Constructs an update object with a given DataSource and SQL.
| |
| SqlUpdate | back to summary |
|---|---|
| public SqlUpdate(DataSource ds, String sql, int[] types) Construct an update object with a given DataSource, SQL and anonymous parameters.
| |
| SqlUpdate | back to summary |
|---|---|
| public SqlUpdate(DataSource ds, String sql, int[] types, int maxRowsAffected) Construct an update object with a given DataSource, SQL, anonymous parameters and specifying the maximum number of rows that may be affected.
| |
| checkRowsAffected | back to summary |
|---|---|
| protected void checkRowsAffected(int rowsAffected) throws JdbcUpdateAffectedIncorrectNumberOfRowsException Check the given number of affected rows against the specified maximum number or required number.
| |
| setMaxRowsAffected | back to summary |
|---|---|
| public void setMaxRowsAffected(int maxRowsAffected) Set the maximum number of rows that may be affected by this update. The default value is 0, which does not limit the number of rows affected.
| |
| setRequiredRowsAffected | back to summary |
|---|---|
| public void setRequiredRowsAffected(int requiredRowsAffected) Set the exact number of rows that must be affected by this update. The default value is 0, which allows any number of rows to be affected. This is an alternative to setting the maximum number of rows that may be affected.
| |
| update | back to summary |
|---|---|
| public int update(Object... params) throws DataAccessException Generic method to execute the update given parameters. All other update methods invoke this method.
| |
| update | back to summary |
|---|---|
| public int update(Object[] params, KeyHolder generatedKeyHolder) throws DataAccessException Method to execute the update given arguments and retrieve the generated keys using a KeyHolder. | |
| update | back to summary |
|---|---|
| public int update() throws DataAccessException Convenience method to execute an update with no parameters. | |
| update | back to summary |
|---|---|
| public int update(int p1) throws DataAccessException Convenient method to execute an update given one int arg. | |
| update | back to summary |
|---|---|
| public int update(int p1, int p2) throws DataAccessException Convenient method to execute an update given two int args. | |
| update | back to summary |
|---|---|
| public int update(long p1) throws DataAccessException Convenient method to execute an update given one long arg. | |
| update | back to summary |
|---|---|
| public int update(long p1, long p2) throws DataAccessException Convenient method to execute an update given two long args. | |
| update | back to summary |
|---|---|
| public int update(String p) throws DataAccessException Convenient method to execute an update given one String arg. | |
| update | back to summary |
|---|---|
| public int update(String p1, String p2) throws DataAccessException Convenient method to execute an update given two String args. | |
| updateByNamedParam | back to summary |
|---|---|
| public int updateByNamedParam(Map<String, ?> paramMap) throws DataAccessException Generic method to execute the update given named parameters. All other update methods invoke this method. | |
| updateByNamedParam | back to summary |
|---|---|
| public int updateByNamedParam(Map<String, ?> paramMap, KeyHolder generatedKeyHolder) throws DataAccessException Method to execute the update given arguments and retrieve the generated keys using a KeyHolder. | |