类 SqlUpdate
- java.lang.Object
- org.springframework.jdbc.object.RdbmsOperation
- org.springframework.jdbc.object.SqlOperation
- org.springframework.jdbc.object.SqlUpdate
- 所有已实现的接口:
InitializingBean
- 直接已知子类:
BatchSqlUpdate
public class SqlUpdate extends SqlOperation
Reusable operation object representing a SQL update.This class provides a number of
update
methods, analogous to theexecute
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.- 作者:
- Rod Johnson, Thomas Risberg, Juergen Hoeller
- 另请参阅:
SqlQuery
字段概要
从类继承的字段 org.springframework.jdbc.object.RdbmsOperation
logger
构造器概要
构造器 构造器 说明 SqlUpdate()
Constructor 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.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected void
checkRowsAffected(int rowsAffected)
Check the given number of affected rows against the specified maximum number or required number.void
setMaxRowsAffected(int maxRowsAffected)
Set the maximum number of rows that may be affected by this update.void
setRequiredRowsAffected(int requiredRowsAffected)
Set the exact number of rows that must be affected by this update.int
update()
Convenience method to execute an update with no parameters.int
update(int p1)
Convenient method to execute an update given one int arg.int
update(int p1, int p2)
Convenient method to execute an update given two int args.int
update(long p1)
Convenient method to execute an update given one long arg.int
update(long p1, long p2)
Convenient method to execute an update given two long args.int
update(Object... params)
Generic method to execute the update given parameters.int
update(Object[] params, KeyHolder generatedKeyHolder)
Method to execute the update given arguments and retrieve the generated keys using a KeyHolder.int
update(String p)
Convenient method to execute an update given one String arg.int
update(String p1, String p2)
Convenient method to execute an update given two String args.int
updateByNamedParam(Map<String,?> paramMap)
Generic method to execute the update given named parameters.int
updateByNamedParam(Map<String,?> paramMap, KeyHolder generatedKeyHolder)
Method to execute the update given arguments and retrieve the generated keys using a KeyHolder.从类继承的方法 org.springframework.jdbc.object.SqlOperation
compileInternal, getParsedSql, newPreparedStatementCreator, newPreparedStatementCreator, newPreparedStatementSetter, onCompileInternal
从类继承的方法 org.springframework.jdbc.object.RdbmsOperation
afterPropertiesSet, allowsUnusedParameters, checkCompiled, compile, declareParameter, getDeclaredParameters, getGeneratedKeysColumnNames, getJdbcTemplate, getResultSetType, getSql, isCompiled, isReturnGeneratedKeys, isUpdatableResults, setDataSource, setFetchSize, setGeneratedKeysColumnNames, setJdbcTemplate, setMaxRows, setParameters, setQueryTimeout, setResultSetType, setReturnGeneratedKeys, setSql, setTypes, setUpdatableResults, supportsLobParameters, validateNamedParameters, validateParameters
构造器详细资料
SqlUpdate
public SqlUpdate()
Constructor to allow use as a JavaBean. DataSource and SQL must be supplied before compilation and use.
SqlUpdate
public SqlUpdate(DataSource ds, String sql)
Constructs an update object with a given DataSource and SQL.- 参数:
ds
- DataSource to use to obtain connectionssql
- SQL statement to execute
SqlUpdate
public SqlUpdate(DataSource ds, String sql, int[] types)
Construct an update object with a given DataSource, SQL and anonymous parameters.- 参数:
ds
- DataSource to use to obtain connectionssql
- SQL statement to executetypes
- SQL types of the parameters, as defined in thejava.sql.Types
class- 另请参阅:
Types
SqlUpdate
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.- 参数:
ds
- DataSource to use to obtain connectionssql
- SQL statement to executetypes
- SQL types of the parameters, as defined in thejava.sql.Types
classmaxRowsAffected
- the maximum number of rows that may be affected by the update- 另请参阅:
Types
方法详细资料
setMaxRowsAffected
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.- 参数:
maxRowsAffected
- the maximum number of rows that can be affected by this update without this class's update method considering it an error
setRequiredRowsAffected
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.
- 参数:
requiredRowsAffected
- the exact number of rows that must be affected by this update without this class's update method considering it an error
checkRowsAffected
protected void checkRowsAffected(int rowsAffected) throws JdbcUpdateAffectedIncorrectNumberOfRowsException
Check the given number of affected rows against the specified maximum number or required number.- 参数:
rowsAffected
- the number of affected rows- 抛出:
JdbcUpdateAffectedIncorrectNumberOfRowsException
- if the actually affected rows are out of bounds- 另请参阅:
setMaxRowsAffected(int)
,setRequiredRowsAffected(int)
update
public int update(Object... params) throws DataAccessException
Generic method to execute the update given parameters. All other update methods invoke this method.- 参数:
params
- array of parameters objects- 返回:
- the number of rows affected by the update
- 抛出:
DataAccessException
update
public int update(Object[] params, KeyHolder generatedKeyHolder) throws DataAccessException
Method to execute the update given arguments and retrieve the generated keys using a KeyHolder.- 参数:
params
- array of parameter objectsgeneratedKeyHolder
- KeyHolder that will hold the generated keys- 返回:
- the number of rows affected by the update
- 抛出:
DataAccessException
update
public int update() throws DataAccessException
Convenience method to execute an update with no parameters.
update
public int update(int p1) throws DataAccessException
Convenient method to execute an update given one int arg.
update
public int update(int p1, int p2) throws DataAccessException
Convenient method to execute an update given two int args.
update
public int update(long p1) throws DataAccessException
Convenient method to execute an update given one long arg.
update
public int update(long p1, long p2) throws DataAccessException
Convenient method to execute an update given two long args.
update
public int update(String p) throws DataAccessException
Convenient method to execute an update given one String arg.
update
public int update(String p1, String p2) throws DataAccessException
Convenient method to execute an update given two String args.
updateByNamedParam
public int updateByNamedParam(Map<String,?> paramMap) throws DataAccessException
Generic method to execute the update given named parameters. All other update methods invoke this method.- 参数:
paramMap
- Map of parameter name to parameter object, matching named parameters specified in the SQL statement- 返回:
- the number of rows affected by the update
- 抛出:
DataAccessException
updateByNamedParam
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.- 参数:
paramMap
- Map of parameter name to parameter object, matching named parameters specified in the SQL statementgeneratedKeyHolder
- KeyHolder that will hold the generated keys- 返回:
- the number of rows affected by the update
- 抛出:
DataAccessException