类 NamedParameterJdbcTemplate
- java.lang.Object
- org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
- 所有已实现的接口:
NamedParameterJdbcOperations
public class NamedParameterJdbcTemplate extends Object implements NamedParameterJdbcOperations
Template class with a basic set of JDBC operations, allowing the use of named parameters rather than traditional '?' placeholders.This class delegates to a wrapped
JdbcTemplate
once the substitution from named parameters to JDBC style '?' placeholders is done at execution time. It also allows for expanding aList
of values to the appropriate number of placeholders.The underlying
JdbcTemplate
is exposed to allow for convenient access to the traditionalJdbcTemplate
methods.NOTE: An instance of this class is thread-safe once configured.
- 从以下版本开始:
- 2.0
- 作者:
- Thomas Risberg, Juergen Hoeller
- 另请参阅:
NamedParameterJdbcOperations
,JdbcTemplate
字段概要
字段 修饰符和类型 字段 说明 static int
DEFAULT_CACHE_LIMIT
Default maximum number of entries for this template's SQL cache: 256
构造器概要
构造器 构造器 说明 NamedParameterJdbcTemplate(DataSource dataSource)
Create a new NamedParameterJdbcTemplate for the givenDataSource
.NamedParameterJdbcTemplate(JdbcOperations classicJdbcTemplate)
Create a new NamedParameterJdbcTemplate for the given classic SpringJdbcTemplate
.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 int[]
batchUpdate(String sql, Map<String,?>[] batchValues)
Executes a batch using the supplied SQL statement with the batch of supplied arguments.int[]
batchUpdate(String sql, SqlParameterSource[] batchArgs)
Execute a batch using the supplied SQL statement with the batch of supplied arguments.<T> T
execute(String sql, Map<String,?> paramMap, PreparedStatementCallback<T> action)
Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement.<T> T
execute(String sql, SqlParameterSource paramSource, PreparedStatementCallback<T> action)
Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement.<T> T
execute(String sql, PreparedStatementCallback<T> action)
Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement.int
getCacheLimit()
Return the maximum number of entries for this template's SQL cache.JdbcOperations
getJdbcOperations()
Expose the classic Spring JdbcTemplate operations to allow invocation of less commonly used methods.protected ParsedSql
getParsedSql(String sql)
Obtain a parsed representation of the given SQL statement.protected PreparedStatementCreator
getPreparedStatementCreator(String sql, SqlParameterSource paramSource)
Build aPreparedStatementCreator
based on the given SQL and named parameters.<T> T
query(String sql, Map<String,?> paramMap, ResultSetExtractor<T> rse)
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, reading the ResultSet with a ResultSetExtractor.void
query(String sql, Map<String,?> paramMap, RowCallbackHandler rch)
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, reading the ResultSet on a per-row basis with a RowCallbackHandler.<T> List<T>
query(String sql, Map<String,?> paramMap, RowMapper<T> rowMapper)
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping each row to a Java object via a RowMapper.<T> T
query(String sql, SqlParameterSource paramSource, ResultSetExtractor<T> rse)
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, reading the ResultSet with a ResultSetExtractor.void
query(String sql, SqlParameterSource paramSource, RowCallbackHandler rch)
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, reading the ResultSet on a per-row basis with a RowCallbackHandler.<T> List<T>
query(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper)
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping each row to a Java object via a RowMapper.<T> T
query(String sql, ResultSetExtractor<T> rse)
Query given SQL to create a prepared statement from SQL, reading the ResultSet with a ResultSetExtractor.void
query(String sql, RowCallbackHandler rch)
Query given SQL to create a prepared statement from SQL, reading the ResultSet on a per-row basis with a RowCallbackHandler.<T> List<T>
query(String sql, RowMapper<T> rowMapper)
Query given SQL to create a prepared statement from SQL, mapping each row to a Java object via a RowMapper.List<Map<String,Object>>
queryForList(String sql, Map<String,?> paramMap)
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.<T> List<T>
queryForList(String sql, Map<String,?> paramMap, Class<T> elementType)
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.List<Map<String,Object>>
queryForList(String sql, SqlParameterSource paramSource)
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.<T> List<T>
queryForList(String sql, SqlParameterSource paramSource, Class<T> elementType)
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.Map<String,Object>
queryForMap(String sql, Map<String,?> paramMap)
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result Map.Map<String,Object>
queryForMap(String sql, SqlParameterSource paramSource)
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result Map.<T> T
queryForObject(String sql, Map<String,?> paramMap, Class<T> requiredType)
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result object.<T> T
queryForObject(String sql, Map<String,?> paramMap, RowMapper<T> rowMapper)
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping a single result row to a Java object via a RowMapper.<T> T
queryForObject(String sql, SqlParameterSource paramSource, Class<T> requiredType)
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result object.<T> T
queryForObject(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper)
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping a single result row to a Java object via a RowMapper.SqlRowSet
queryForRowSet(String sql, Map<String,?> paramMap)
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a SqlRowSet.SqlRowSet
queryForRowSet(String sql, SqlParameterSource paramSource)
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a SqlRowSet.void
setCacheLimit(int cacheLimit)
Specify the maximum number of entries for this template's SQL cache.int
update(String sql, Map<String,?> paramMap)
Issue an update via a prepared statement, binding the given arguments.int
update(String sql, SqlParameterSource paramSource)
Issue an update via a prepared statement, binding the given arguments.int
update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder)
Issue an update via a prepared statement, binding the given arguments, returning generated keys.int
update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder, String[] keyColumnNames)
Issue an update via a prepared statement, binding the given arguments, returning generated keys.
字段详细资料
DEFAULT_CACHE_LIMIT
public static final int DEFAULT_CACHE_LIMIT
Default maximum number of entries for this template's SQL cache: 256- 另请参阅:
- 常量字段值
构造器详细资料
NamedParameterJdbcTemplate
public NamedParameterJdbcTemplate(DataSource dataSource)
Create a new NamedParameterJdbcTemplate for the givenDataSource
.Creates a classic Spring
JdbcTemplate
and wraps it.- 参数:
dataSource
- the JDBC DataSource to access
NamedParameterJdbcTemplate
public NamedParameterJdbcTemplate(JdbcOperations classicJdbcTemplate)
Create a new NamedParameterJdbcTemplate for the given classic SpringJdbcTemplate
.- 参数:
classicJdbcTemplate
- the classic Spring JdbcTemplate to wrap
方法详细资料
getJdbcOperations
public JdbcOperations getJdbcOperations()
Expose the classic Spring JdbcTemplate operations to allow invocation of less commonly used methods.
setCacheLimit
public void setCacheLimit(int cacheLimit)
Specify the maximum number of entries for this template's SQL cache. Default is 256.
getCacheLimit
public int getCacheLimit()
Return the maximum number of entries for this template's SQL cache.
execute
public <T> T execute(String sql, SqlParameterSource paramSource, PreparedStatementCallback<T> action) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement. This allows for implementing arbitrary data access operations on a single Statement, within Spring's managed JDBC environment: that is, participating in Spring-managed transactions and converting JDBC SQLExceptions into Spring's DataAccessException hierarchy.The callback action can return a result object, for example a domain object or a collection of domain objects.
- 指定者:
execute
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL to executeparamSource
- container of arguments to bind to the queryaction
- callback object that specifies the action- 返回:
- a result object returned by the action, or
null
- 抛出:
DataAccessException
- if there is any problem
execute
public <T> T execute(String sql, Map<String,?> paramMap, PreparedStatementCallback<T> action) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement. This allows for implementing arbitrary data access operations on a single Statement, within Spring's managed JDBC environment: that is, participating in Spring-managed transactions and converting JDBC SQLExceptions into Spring's DataAccessException hierarchy.The callback action can return a result object, for example a domain object or a collection of domain objects.
- 指定者:
execute
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL to executeparamMap
- map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)action
- callback object that specifies the action- 返回:
- a result object returned by the action, or
null
- 抛出:
DataAccessException
- if there is any problem
execute
public <T> T execute(String sql, PreparedStatementCallback<T> action) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement. This allows for implementing arbitrary data access operations on a single Statement, within Spring's managed JDBC environment: that is, participating in Spring-managed transactions and converting JDBC SQLExceptions into Spring's DataAccessException hierarchy.The callback action can return a result object, for example a domain object or a collection of domain objects.
- 指定者:
execute
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL to executeaction
- callback object that specifies the action- 返回:
- a result object returned by the action, or
null
- 抛出:
DataAccessException
- if there is any problem
query
public <T> T query(String sql, SqlParameterSource paramSource, ResultSetExtractor<T> rse) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, reading the ResultSet with a ResultSetExtractor.- 指定者:
query
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL query to executeparamSource
- container of arguments to bind to the queryrse
- object that will extract results- 返回:
- an arbitrary result object, as returned by the ResultSetExtractor
- 抛出:
DataAccessException
- if the query fails
query
public <T> T query(String sql, Map<String,?> paramMap, ResultSetExtractor<T> rse) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, reading the ResultSet with a ResultSetExtractor.- 指定者:
query
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL query to executeparamMap
- map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)rse
- object that will extract results- 返回:
- an arbitrary result object, as returned by the ResultSetExtractor
- 抛出:
DataAccessException
- if the query fails
query
public <T> T query(String sql, ResultSetExtractor<T> rse) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL, reading the ResultSet with a ResultSetExtractor.Note: In contrast to the JdbcOperations method with the same signature, this query variant always uses a PreparedStatement. It is effectively equivalent to a query call with an empty parameter Map.
- 指定者:
query
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL query to executerse
- object that will extract results- 返回:
- an arbitrary result object, as returned by the ResultSetExtractor
- 抛出:
DataAccessException
- if the query fails
query
public void query(String sql, SqlParameterSource paramSource, RowCallbackHandler rch) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, reading the ResultSet on a per-row basis with a RowCallbackHandler.- 指定者:
query
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL query to executeparamSource
- container of arguments to bind to the queryrch
- object that will extract results, one row at a time- 抛出:
DataAccessException
- if the query fails
query
public void query(String sql, Map<String,?> paramMap, RowCallbackHandler rch) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, reading the ResultSet on a per-row basis with a RowCallbackHandler.- 指定者:
query
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL query to executeparamMap
- map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)rch
- object that will extract results, one row at a time- 抛出:
DataAccessException
- if the query fails
query
public void query(String sql, RowCallbackHandler rch) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL, reading the ResultSet on a per-row basis with a RowCallbackHandler.Note: In contrast to the JdbcOperations method with the same signature, this query variant always uses a PreparedStatement. It is effectively equivalent to a query call with an empty parameter Map.
- 指定者:
query
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL query to executerch
- object that will extract results, one row at a time- 抛出:
DataAccessException
- if the query fails
query
public <T> List<T> query(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping each row to a Java object via a RowMapper.- 指定者:
query
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL query to executeparamSource
- container of arguments to bind to the queryrowMapper
- object that will map one object per row- 返回:
- the result List, containing mapped objects
- 抛出:
DataAccessException
- if the query fails
query
public <T> List<T> query(String sql, Map<String,?> paramMap, RowMapper<T> rowMapper) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping each row to a Java object via a RowMapper.- 指定者:
query
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL query to executeparamMap
- map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)rowMapper
- object that will map one object per row- 返回:
- the result List, containing mapped objects
- 抛出:
DataAccessException
- if the query fails
query
public <T> List<T> query(String sql, RowMapper<T> rowMapper) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL, mapping each row to a Java object via a RowMapper.Note: In contrast to the JdbcOperations method with the same signature, this query variant always uses a PreparedStatement. It is effectively equivalent to a query call with an empty parameter Map.
- 指定者:
query
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL query to executerowMapper
- object that will map one object per row- 返回:
- the result List, containing mapped objects
- 抛出:
DataAccessException
- if the query fails
queryForObject
public <T> T queryForObject(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping a single result row to a Java object via a RowMapper.- 指定者:
queryForObject
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL query to executeparamSource
- container of arguments to bind to the queryrowMapper
- object that will map one object per row- 返回:
- the single mapped object (may be
null
if the givenRowMapper
returned null) - 抛出:
IncorrectResultSizeDataAccessException
- if the query does not return exactly one row, or does not return exactly one column in that rowDataAccessException
- if the query fails
queryForObject
public <T> T queryForObject(String sql, Map<String,?> paramMap, RowMapper<T> rowMapper) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping a single result row to a Java object via a RowMapper.- 指定者:
queryForObject
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL query to executeparamMap
- map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)rowMapper
- object that will map one object per row- 返回:
- the single mapped object (may be
null
if the givenRowMapper
returned null) - 抛出:
IncorrectResultSizeDataAccessException
- if the query does not return exactly one row, or does not return exactly one column in that rowDataAccessException
- if the query fails
queryForObject
public <T> T queryForObject(String sql, SqlParameterSource paramSource, Class<T> requiredType) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result object.The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.
- 指定者:
queryForObject
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL query to executeparamSource
- container of arguments to bind to the queryrequiredType
- the type that the result object is expected to match- 返回:
- the result object of the required type, or
null
in case of SQL NULL - 抛出:
IncorrectResultSizeDataAccessException
- if the query does not return exactly one row, or does not return exactly one column in that rowDataAccessException
- if the query fails- 另请参阅:
JdbcTemplate.queryForObject(String, Class)
queryForObject
public <T> T queryForObject(String sql, Map<String,?> paramMap, Class<T> requiredType) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result object.The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.
- 指定者:
queryForObject
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL query to executeparamMap
- map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)requiredType
- the type that the result object is expected to match- 返回:
- the result object of the required type, or
null
in case of SQL NULL - 抛出:
IncorrectResultSizeDataAccessException
- if the query does not return exactly one row, or does not return exactly one column in that rowDataAccessException
- if the query fails- 另请参阅:
JdbcTemplate.queryForObject(String, Class)
queryForMap
public Map<String,Object> queryForMap(String sql, SqlParameterSource paramSource) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result Map.The query is expected to be a single row query; the result row will be mapped to a Map (one entry for each column, using the column name as the key).
- 指定者:
queryForMap
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL query to executeparamSource
- container of arguments to bind to the query- 返回:
- the result Map (one entry for each column, using the column name as the key)
- 抛出:
IncorrectResultSizeDataAccessException
- if the query does not return exactly one rowDataAccessException
- if the query fails- 另请参阅:
JdbcTemplate.queryForMap(String)
,ColumnMapRowMapper
queryForMap
public Map<String,Object> queryForMap(String sql, Map<String,?> paramMap) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result Map. The queryForMap() methods defined by this interface are appropriate when you don't have a domain model. Otherwise, consider using one of the queryForObject() methods.The query is expected to be a single row query; the result row will be mapped to a Map (one entry for each column, using the column name as the key).
- 指定者:
queryForMap
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL query to executeparamMap
- map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)- 返回:
- the result Map (one entry for each column, using the column name as the key)
- 抛出:
IncorrectResultSizeDataAccessException
- if the query does not return exactly one rowDataAccessException
- if the query fails- 另请参阅:
JdbcTemplate.queryForMap(String)
,ColumnMapRowMapper
queryForList
public <T> List<T> queryForList(String sql, SqlParameterSource paramSource, Class<T> elementType) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.
- 指定者:
queryForList
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL query to executeparamSource
- container of arguments to bind to the queryelementType
- the required type of element in the result list (for example,Integer.class
)- 返回:
- a List of objects that match the specified element type
- 抛出:
DataAccessException
- if the query fails- 另请参阅:
JdbcTemplate.queryForList(String, Class)
,SingleColumnRowMapper
queryForList
public <T> List<T> queryForList(String sql, Map<String,?> paramMap, Class<T> elementType) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.
- 指定者:
queryForList
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL query to executeparamMap
- map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)elementType
- the required type of element in the result list (for example,Integer.class
)- 返回:
- a List of objects that match the specified element type
- 抛出:
DataAccessException
- if the query fails- 另请参阅:
JdbcTemplate.queryForList(String, Class)
,SingleColumnRowMapper
queryForList
public List<Map<String,Object>> queryForList(String sql, SqlParameterSource paramSource) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.The results will be mapped to a List (one entry for each row) of Maps (one entry for each column, using the column name as the key). Each element in the list will be of the form returned by this interface's
queryForMap
methods.- 指定者:
queryForList
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL query to executeparamSource
- container of arguments to bind to the query- 返回:
- a List that contains a Map per row
- 抛出:
DataAccessException
- if the query fails- 另请参阅:
JdbcTemplate.queryForList(String)
queryForList
public List<Map<String,Object>> queryForList(String sql, Map<String,?> paramMap) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.The results will be mapped to a List (one entry for each row) of Maps (one entry for each column, using the column name as the key). Each element in the list will be of the form returned by this interface's
queryForMap
methods.- 指定者:
queryForList
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL query to executeparamMap
- map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)- 返回:
- a List that contains a Map per row
- 抛出:
DataAccessException
- if the query fails- 另请参阅:
JdbcTemplate.queryForList(String)
queryForRowSet
public SqlRowSet queryForRowSet(String sql, SqlParameterSource paramSource) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a SqlRowSet.The results will be mapped to an SqlRowSet which holds the data in a disconnected fashion. This wrapper will translate any SQLExceptions thrown.
Note that, for the default implementation, JDBC RowSet support needs to be available at runtime: by default, Sun's
com.sun.rowset.CachedRowSetImpl
class is used, which is part of JDK 1.5+ and also available separately as part of Sun's JDBC RowSet Implementations download (rowset.jar).- 指定者:
queryForRowSet
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL query to executeparamSource
- container of arguments to bind to the query- 返回:
- a SqlRowSet representation (possibly a wrapper around a
javax.sql.rowset.CachedRowSet
) - 抛出:
DataAccessException
- if there is any problem executing the query- 另请参阅:
JdbcTemplate.queryForRowSet(String)
,SqlRowSetResultSetExtractor
,CachedRowSet
queryForRowSet
public SqlRowSet queryForRowSet(String sql, Map<String,?> paramMap) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a SqlRowSet.The results will be mapped to an SqlRowSet which holds the data in a disconnected fashion. This wrapper will translate any SQLExceptions thrown.
Note that, for the default implementation, JDBC RowSet support needs to be available at runtime: by default, Sun's
com.sun.rowset.CachedRowSetImpl
class is used, which is part of JDK 1.5+ and also available separately as part of Sun's JDBC RowSet Implementations download (rowset.jar).- 指定者:
queryForRowSet
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL query to executeparamMap
- map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)- 返回:
- a SqlRowSet representation (possibly a wrapper around a
javax.sql.rowset.CachedRowSet
) - 抛出:
DataAccessException
- if there is any problem executing the query- 另请参阅:
JdbcTemplate.queryForRowSet(String)
,SqlRowSetResultSetExtractor
,CachedRowSet
update
public int update(String sql, SqlParameterSource paramSource) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Issue an update via a prepared statement, binding the given arguments.- 指定者:
update
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL containing named parametersparamSource
- container of arguments and SQL types to bind to the query- 返回:
- the number of rows affected
- 抛出:
DataAccessException
- if there is any problem issuing the update
update
public int update(String sql, Map<String,?> paramMap) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Issue an update via a prepared statement, binding the given arguments.- 指定者:
update
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL containing named parametersparamMap
- map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)- 返回:
- the number of rows affected
- 抛出:
DataAccessException
- if there is any problem issuing the update
update
public int update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Issue an update via a prepared statement, binding the given arguments, returning generated keys.- 指定者:
update
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL containing named parametersparamSource
- container of arguments and SQL types to bind to the querygeneratedKeyHolder
- aKeyHolder
that will hold the generated keys- 返回:
- the number of rows affected
- 抛出:
DataAccessException
- if there is any problem issuing the update- 另请参阅:
MapSqlParameterSource
,GeneratedKeyHolder
update
public int update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder, String[] keyColumnNames) throws DataAccessException
从接口复制的说明:NamedParameterJdbcOperations
Issue an update via a prepared statement, binding the given arguments, returning generated keys.- 指定者:
update
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL containing named parametersparamSource
- container of arguments and SQL types to bind to the querygeneratedKeyHolder
- aKeyHolder
that will hold the generated keyskeyColumnNames
- names of the columns that will have keys generated for them- 返回:
- the number of rows affected
- 抛出:
DataAccessException
- if there is any problem issuing the update- 另请参阅:
MapSqlParameterSource
,GeneratedKeyHolder
batchUpdate
public int[] batchUpdate(String sql, Map<String,?>[] batchValues)
从接口复制的说明:NamedParameterJdbcOperations
Executes a batch using the supplied SQL statement with the batch of supplied arguments.- 指定者:
batchUpdate
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL statement to executebatchValues
- the array of Maps containing the batch of arguments for the query- 返回:
- an array containing the numbers of rows affected by each update in the batch
batchUpdate
public int[] batchUpdate(String sql, SqlParameterSource[] batchArgs)
从接口复制的说明:NamedParameterJdbcOperations
Execute a batch using the supplied SQL statement with the batch of supplied arguments.- 指定者:
batchUpdate
在接口中NamedParameterJdbcOperations
- 参数:
sql
- the SQL statement to executebatchArgs
- the array ofSqlParameterSource
containing the batch of arguments for the query- 返回:
- an array containing the numbers of rows affected by each update in the batch
getPreparedStatementCreator
protected PreparedStatementCreator getPreparedStatementCreator(String sql, SqlParameterSource paramSource)
Build aPreparedStatementCreator
based on the given SQL and named parameters.Note: Directly called from all
query
variants. Not used for theupdate
variant with generated key handling.- 参数:
sql
- the SQL statement to executeparamSource
- container of arguments to bind- 返回:
- the corresponding
PreparedStatementCreator
getParsedSql
protected ParsedSql getParsedSql(String sql)
Obtain a parsed representation of the given SQL statement.The default implementation uses an LRU cache with an upper limit of 256 entries.
- 参数:
sql
- the original SQL statement- 返回:
- a representation of the parsed SQL statement