Package org.springframework.jdbc.object
Class SqlUpdate
java.lang.Object
org.springframework.jdbc.object.RdbmsOperation
org.springframework.jdbc.object.SqlOperation
org.springframework.jdbc.object.SqlUpdate
- All Implemented Interfaces:
- InitializingBean
- Direct Known Subclasses:
- BatchSqlUpdate
Reusable operation object representing an SQL update.
 
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.
- Author:
- Rod Johnson, Thomas Risberg, Juergen Hoeller
- See Also:
- 
Field SummaryFields inherited from class org.springframework.jdbc.object.RdbmsOperationlogger
- 
Constructor SummaryConstructorsConstructorDescriptionConstructor to allow use as a JavaBean.SqlUpdate(DataSource ds, String sql) Constructs an update object with a given DataSource and SQL.SqlUpdate(DataSource ds, String sql, int[] types) Construct an update object with a given DataSource, SQL and anonymous parameters.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.
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidcheckRowsAffected(int rowsAffected) Check the given number of affected rows against the specified maximum number or required number.voidsetMaxRowsAffected(int maxRowsAffected) Set the maximum number of rows that may be affected by this update.voidsetRequiredRowsAffected(int requiredRowsAffected) Set the exact number of rows that must be affected by this update.intupdate()Convenience method to execute an update with no parameters.intupdate(int p1) Convenient method to execute an update given one int arg.intupdate(int p1, int p2) Convenient method to execute an update given two int args.intupdate(long p1) Convenient method to execute an update given one long arg.intupdate(long p1, long p2) Convenient method to execute an update given two long args.intGeneric method to execute the update given parameters.intMethod to execute the update given arguments and retrieve the generated keys using a KeyHolder.intConvenient method to execute an update given one String arg.intConvenient method to execute an update given two String args.intupdateByNamedParam(Map<String, ?> paramMap) Generic method to execute the update given named parameters.intupdateByNamedParam(Map<String, ?> paramMap, KeyHolder generatedKeyHolder) Method to execute the update given arguments and retrieve the generated keys using a KeyHolder.Methods inherited from class org.springframework.jdbc.object.SqlOperationcompileInternal, getParsedSql, newPreparedStatementCreator, newPreparedStatementCreator, newPreparedStatementSetter, onCompileInternalMethods inherited from class org.springframework.jdbc.object.RdbmsOperationafterPropertiesSet, allowsUnusedParameters, checkCompiled, compile, declareParameter, getDeclaredParameters, getGeneratedKeysColumnNames, getJdbcTemplate, getResultSetType, getSql, isCompiled, isReturnGeneratedKeys, isUpdatableResults, resolveSql, setDataSource, setFetchSize, setGeneratedKeysColumnNames, setJdbcTemplate, setMaxRows, setParameters, setQueryTimeout, setResultSetType, setReturnGeneratedKeys, setSql, setTypes, setUpdatableResults, supportsLobParameters, validateNamedParameters, validateParameters
- 
Constructor Details- 
SqlUpdatepublic SqlUpdate()Constructor to allow use as a JavaBean. DataSource and SQL must be supplied before compilation and use.
- 
SqlUpdateConstructs an update object with a given DataSource and SQL.- Parameters:
- ds- the DataSource to use to obtain connections
- sql- the SQL statement to execute
 
- 
SqlUpdateConstruct an update object with a given DataSource, SQL and anonymous parameters.- Parameters:
- ds- the DataSource to use to obtain connections
- sql- the SQL statement to execute
- types- the SQL types of the parameters, as defined in the- java.sql.Typesclass
- See Also:
 
- 
SqlUpdateConstruct an update object with a given DataSource, SQL, anonymous parameters and specifying the maximum number of rows that may be affected.- Parameters:
- ds- the DataSource to use to obtain connections
- sql- the SQL statement to execute
- types- the SQL types of the parameters, as defined in the- java.sql.Typesclass
- maxRowsAffected- the maximum number of rows that may be affected by the update
- See Also:
 
 
- 
- 
Method Details- 
setMaxRowsAffectedpublic 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.- Parameters:
- maxRowsAffected- the maximum number of rows that can be affected by this update without this class's update method considering it an error
 
- 
setRequiredRowsAffectedpublic 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. - Parameters:
- requiredRowsAffected- the exact number of rows that must be affected by this update without this class's update method considering it an error
 
- 
checkRowsAffectedprotected void checkRowsAffected(int rowsAffected) throws JdbcUpdateAffectedIncorrectNumberOfRowsException Check the given number of affected rows against the specified maximum number or required number.- Parameters:
- rowsAffected- the number of affected rows
- Throws:
- JdbcUpdateAffectedIncorrectNumberOfRowsException- if the actually affected rows are out of bounds
- See Also:
 
- 
updateGeneric method to execute the update given parameters. All other update methods invoke this method.- Parameters:
- params- array of parameters objects
- Returns:
- the number of rows affected by the update
- Throws:
- DataAccessException
 
- 
updateMethod to execute the update given arguments and retrieve the generated keys using a KeyHolder.- Parameters:
- params- array of parameter objects
- generatedKeyHolder- the KeyHolder that will hold the generated keys
- Returns:
- the number of rows affected by the update
- Throws:
- DataAccessException
 
- 
updateConvenience method to execute an update with no parameters.- Throws:
- DataAccessException
 
- 
updateConvenient method to execute an update given one int arg.- Throws:
- DataAccessException
 
- 
updateConvenient method to execute an update given two int args.- Throws:
- DataAccessException
 
- 
updateConvenient method to execute an update given one long arg.- Throws:
- DataAccessException
 
- 
updateConvenient method to execute an update given two long args.- Throws:
- DataAccessException
 
- 
updateConvenient method to execute an update given one String arg.- Throws:
- DataAccessException
 
- 
updateConvenient method to execute an update given two String args.- Throws:
- DataAccessException
 
- 
updateByNamedParamGeneric method to execute the update given named parameters. All other update methods invoke this method.- Parameters:
- paramMap- a Map of parameter name to parameter object, matching named parameters specified in the SQL statement
- Returns:
- the number of rows affected by the update
- Throws:
- DataAccessException
 
- 
updateByNamedParampublic int updateByNamedParam(Map<String, ?> paramMap, KeyHolder generatedKeyHolder) throws DataAccessExceptionMethod to execute the update given arguments and retrieve the generated keys using a KeyHolder.- Parameters:
- paramMap- a Map of parameter name to parameter object, matching named parameters specified in the SQL statement
- generatedKeyHolder- the KeyHolder that will hold the generated keys
- Returns:
- the number of rows affected by the update
- Throws:
- DataAccessException
 
 
-