站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Spring Framework 2.0.5 API 文档英文版

NamedParameterJdbcTemplate (Spring Framework API 2.0) - Spring Framework 2.0.5 API 文档英文版

The Spring Framework

org.springframework.jdbc.core.namedparam
Class NamedParameterJdbcTemplate

java.lang.Object
  extended by org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
All Implemented Interfaces:
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 a List of values to the appropriate number of placeholders.

The underlying JdbcTemplate is exposed to allow for convenient access to the traditional JdbcTemplate methods.

Since:
2.0
Author:
Thomas Risberg, Juergen Hoeller
See Also:
NamedParameterJdbcOperations, JdbcTemplate

Constructor Summary
NamedParameterJdbcTemplate(DataSource dataSource)
          Create a new NamedParameterJdbcTemplate for the given DataSource.
NamedParameterJdbcTemplate(JdbcOperations classicJdbcTemplate)
          Create a new NamedParameterJdbcTemplate for the given classic Spring JdbcTemplate.
 
Method Summary
 Object execute(String sql, Map paramMap, PreparedStatementCallback action)
          Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement.
 Object execute(String sql, SqlParameterSource paramSource, PreparedStatementCallback action)
          Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement.
 JdbcOperations getJdbcOperations()
          Expose the classic Spring JdbcTemplate 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 a PreparedStatementCreator based on the given SQL and named parameters.
 Object query(String sql, Map paramMap, ResultSetExtractor 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 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.
 List query(String sql, Map paramMap, RowMapper 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.
 Object query(String sql, SqlParameterSource paramSource, ResultSetExtractor 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.
 List query(String sql, SqlParameterSource paramSource, RowMapper 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.
 int queryForInt(String sql, Map paramMap)
          Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, resulting in an int value.
 int queryForInt(String sql, SqlParameterSource paramSource)
          Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, resulting in an int value.
 List queryForList(String sql, Map 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.
 List queryForList(String sql, Map paramMap, Class 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 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.
 List queryForList(String sql, SqlParameterSource paramSource, Class 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.
 long queryForLong(String sql, Map paramMap)
          Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, resulting in a long value.
 long queryForLong(String sql, SqlParameterSource paramSource)
          Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, resulting in a long value.
 Map queryForMap(String sql, Map 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 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.
 Object queryForObject(String sql, Map paramMap, Class 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.
 Object queryForObject(String sql, Map paramMap, RowMapper 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.
 Object queryForObject(String sql, SqlParameterSource paramSource, Class 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.
 Object queryForObject(String sql, SqlParameterSource paramSource, RowMapper 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 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.
 int update(String sql, Map 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NamedParameterJdbcTemplate

public NamedParameterJdbcTemplate(DataSource dataSource)
Create a new NamedParameterJdbcTemplate for the given DataSource.

Creates a classic Spring JdbcTemplate and wraps it.

Parameters:
dataSource - the JDBC DataSource to access

NamedParameterJdbcTemplate

public NamedParameterJdbcTemplate(JdbcOperations classicJdbcTemplate)
Create a new NamedParameterJdbcTemplate for the given classic Spring JdbcTemplate.

Parameters:
classicJdbcTemplate - the classic Spring JdbcTemplate to wrap
Method Detail

getJdbcOperations

public JdbcOperations getJdbcOperations()
Expose the classic Spring JdbcTemplate to allow invocation of less commonly used methods.

Specified by:
getJdbcOperations in interface NamedParameterJdbcOperations

execute

public Object execute(String sql,
                      SqlParameterSource paramSource,
                      PreparedStatementCallback action)
               throws DataAccessException
Description copied from interface: 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.

Specified by:
execute in interface NamedParameterJdbcOperations
Parameters:
sql - SQL to execute
paramSource - container of arguments to bind to the query
action - callback object that specifies the action
Returns:
a result object returned by the action, or null
Throws:
DataAccessException - if there is any problem

execute

public Object execute(String sql,
                      Map paramMap,
                      PreparedStatementCallback action)
               throws DataAccessException
Description copied from interface: 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.

Specified by:
execute in interface NamedParameterJdbcOperations
Parameters:
sql - SQL to execute
paramMap - 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
Returns:
a result object returned by the action, or null
Throws:
DataAccessException - if there is any problem

query

public Object query(String sql,
                    SqlParameterSource paramSource,
                    ResultSetExtractor rse)
             throws DataAccessException
Description copied from interface: 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.

Specified by:
query in interface NamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramSource - container of arguments to bind to the query
rse - object that will extract results
Returns:
an arbitrary result object, as returned by the ResultSetExtractor
Throws:
DataAccessException - if the query fails

query

public Object query(String sql,
                    Map paramMap,
                    ResultSetExtractor rse)
             throws DataAccessException
Description copied from interface: 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.

Specified by:
query in interface NamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramMap - 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
Returns:
an arbitrary result object, as returned by the ResultSetExtractor
Throws:
DataAccessException - if the query fails

query

public void query(String sql,
                  SqlParameterSource paramSource,
                  RowCallbackHandler rch)
           throws DataAccessException
Description copied from interface: 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.

Specified by:
query in interface NamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramSource - container of arguments to bind to the query
rch - object that will extract results, one row at a time
Throws:
DataAccessException - if the query fails

query

public void query(String sql,
                  Map paramMap,
                  RowCallbackHandler rch)
           throws DataAccessException
Description copied from interface: 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.

Specified by:
query in interface NamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramMap - 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
Throws:
DataAccessException - if the query fails

query

public List query(String sql,
                  SqlParameterSource paramSource,
                  RowMapper rowMapper)
           throws DataAccessException
Description copied from interface: 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.

Specified by:
query in interface NamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramSource - container of arguments to bind to the query
rowMapper - object that will map one object per row
Returns:
the result List, containing mapped objects
Throws:
DataAccessException - if the query fails

query

public List query(String sql,
                  Map paramMap,
                  RowMapper rowMapper)
           throws DataAccessException
Description copied from interface: 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.

Specified by:
query in interface NamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramMap - 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
Returns:
the result List, containing mapped objects
Throws:
DataAccessException - if the query fails

queryForObject

public Object queryForObject(String sql,
                             SqlParameterSource paramSource,
                             RowMapper rowMapper)
                      throws DataAccessException
Description copied from interface: 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.

Specified by:
queryForObject in interface NamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramSource - container of arguments to bind to the query
rowMapper - object that will map one object per row
Returns:
the single mapped object
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row
DataAccessException - if the query fails

queryForObject

public Object queryForObject(String sql,
                             Map paramMap,
                             RowMapper rowMapper)
                      throws DataAccessException
Description copied from interface: 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.

Specified by:
queryForObject in interface NamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramMap - 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
Returns:
the single mapped object
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row
DataAccessException - if the query fails

queryForObject

public Object queryForObject(String sql,
                             SqlParameterSource paramSource,
                             Class requiredType)
                      throws DataAccessException
Description copied from interface: 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.

Specified by:
queryForObject in interface NamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramSource - container of arguments to bind to the query
requiredType - the type that the result object is expected to match
Returns:
the result object of the required type, or null in case of SQL NULL
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row
DataAccessException - if the query fails
See Also:
JdbcTemplate.queryForObject(String, Class)

queryForObject

public Object queryForObject(String sql,
                             Map paramMap,
                             Class requiredType)
                      throws DataAccessException
Description copied from interface: 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.

Specified by:
queryForObject in interface NamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramMap - 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
Returns:
the result object of the required type, or null in case of SQL NULL
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row
DataAccessException - if the query fails
See Also:
JdbcTemplate.queryForObject(String, Class)

queryForMap

public Map queryForMap(String sql,
                       SqlParameterSource paramSource)
                throws DataAccessException
Description copied from interface: 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).

Specified by:
queryForMap in interface NamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramSource - container of arguments to bind to the query
Returns:
the result Map (one entry for each column, using the column name as the key)
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row
DataAccessException - if the query fails
See Also:
JdbcTemplate.queryForMap(String), ColumnMapRowMapper

queryForMap

public Map queryForMap(String sql,
                       Map paramMap)
                throws DataAccessException
Description copied from interface: 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).

Specified by:
queryForMap in interface NamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramMap - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
Returns:
the result Map (one entry for each column, using the column name as the key)
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row
DataAccessException - if the query fails
See Also:
JdbcTemplate.queryForMap(String), ColumnMapRowMapper

queryForLong

public long queryForLong(String sql,
                         SqlParameterSource paramSource)
                  throws DataAccessException
Description copied from interface: NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, resulting in a long value.

The query is expected to be a single row/single column query that results in a long value.

Specified by:
queryForLong in interface NamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramSource - container of arguments to bind to the query
Returns:
the long value, or 0 in case of SQL NULL
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row
DataAccessException - if the query fails
See Also:
JdbcTemplate.queryForLong(String)

queryForLong

public long queryForLong(String sql,
                         Map paramMap)
                  throws DataAccessException
Description copied from interface: NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, resulting in a long value.

The query is expected to be a single row/single column query that results in a long value.

Specified by:
queryForLong in interface NamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramMap - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
Returns:
the long value, or 0 in case of SQL NULL
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row
DataAccessException - if the query fails
See Also:
JdbcTemplate.queryForLong(String)

queryForInt

public int queryForInt(String sql,
                       SqlParameterSource paramSource)
                throws DataAccessException
Description copied from interface: NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, resulting in an int value.

The query is expected to be a single row/single column query that results in an int value.

Specified by:
queryForInt in interface NamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramSource - container of arguments to bind to the query
Returns:
the int value, or 0 in case of SQL NULL
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row
DataAccessException - if the query fails
See Also:
JdbcTemplate.queryForInt(String)

queryForInt

public int queryForInt(String sql,
                       Map paramMap)
                throws DataAccessException
Description copied from interface: NamedParameterJdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, resulting in an int value.

The query is expected to be a single row/single column query that results in an int value.

Specified by:
queryForInt in interface NamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramMap - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
Returns:
the int value, or 0 in case of SQL NULL
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row
DataAccessException - if the query fails
See Also:
JdbcTemplate.queryForInt(String)

queryForList

public List queryForList(String sql,
                         SqlParameterSource paramSource,
                         Class elementType)
                  throws DataAccessException
Description copied from interface: 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.

Specified by:
queryForList in interface NamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramSource - container of arguments to bind to the query
elementType - the required type of element in the result list (for example, Integer.class)
Returns:
a List of objects that match the specified element type
Throws:
DataAccessException - if the query fails
See Also:
JdbcTemplate.queryForList(String, Class), SingleColumnRowMapper

queryForList

public List queryForList(String sql,
                         Map paramMap,
                         Class elementType)
                  throws DataAccessException
Description copied from interface: 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.

Specified by:
queryForList in interface NamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramMap - 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)
Returns:
a List of objects that match the specified element type
Throws:
DataAccessException - if the query fails
See Also:
JdbcTemplate.queryForList(String, Class), SingleColumnRowMapper

queryForList

public List queryForList(String sql,
                         SqlParameterSource paramSource)
                  throws DataAccessException
Description copied from interface: 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). Thus Each element in the list will be of the form returned by this interface's queryForMap() methods.

Specified by:
queryForList in interface NamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramSource - container of arguments to bind to the query
Returns:
a List that contains a Map per row
Throws:
DataAccessException - if the query fails
See Also:
JdbcTemplate.queryForList(String)

queryForList

public List queryForList(String sql,
                         Map paramMap)
                  throws DataAccessException
Description copied from interface: 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.

Specified by:
queryForList in interface NamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramMap - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
Returns:
a List that contains a Map per row
Throws:
DataAccessException - if the query fails
See Also:
JdbcTemplate.queryForList(String)

queryForRowSet

public SqlRowSet queryForRowSet(String sql,
                                SqlParameterSource paramSource)
                         throws DataAccessException
Description copied from interface: 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 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).

Specified by:
queryForRowSet in interface NamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramSource - container of arguments to bind to the query
Returns:
a SqlRowSet representation (possibly a wrapper around a javax.sql.rowset.CachedRowSet)
Throws:
DataAccessException - if there is any problem executing the query
See Also:
JdbcTemplate.queryForRowSet(String), SqlRowSetResultSetExtractor, CachedRowSet

queryForRowSet

public SqlRowSet queryForRowSet(String sql,
                                Map paramMap)
                         throws DataAccessException
Description copied from interface: 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 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).

Specified by:
queryForRowSet in interface NamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramMap - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
Returns:
a SqlRowSet representation (possibly a wrapper around a javax.sql.rowset.CachedRowSet)
Throws:
DataAccessException - if there is any problem executing the query
See Also:
JdbcTemplate.queryForRowSet(String), SqlRowSetResultSetExtractor, CachedRowSet

update

public int update(String sql,
                  SqlParameterSource paramSource)
           throws DataAccessException
Description copied from interface: NamedParameterJdbcOperations
Issue an update via a prepared statement, binding the given arguments.

Specified by:
update in interface NamedParameterJdbcOperations
Parameters:
sql - SQL containing named parameters
paramSource - container of arguments and SQL types to bind to the query
Returns:
the number of rows affected
Throws:
DataAccessException - if there is any problem issuing the update

update

public int update(String sql,
                  Map paramMap)
           throws DataAccessException
Description copied from interface: NamedParameterJdbcOperations
Issue an update via a prepared statement, binding the given arguments.

Specified by:
update in interface NamedParameterJdbcOperations
Parameters:
sql - SQL containing named parameters
paramMap - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
Returns:
the number of rows affected
Throws:
DataAccessException - if there is any problem issuing the update

update

public int update(String sql,
                  SqlParameterSource paramSource,
                  KeyHolder generatedKeyHolder)
           throws DataAccessException
Description copied from interface: NamedParameterJdbcOperations
Issue an update via a prepared statement, binding the given arguments, returning generated keys.

Specified by:
update in interface NamedParameterJdbcOperations
Parameters:
sql - SQL containing named parameters
paramSource - container of arguments and SQL types to bind to the query
generatedKeyHolder - KeyHolder that will hold the generated keys
Returns:
the number of rows affected
Throws:
DataAccessException - if there is any problem issuing the update
See Also:
MapSqlParameterSource, GeneratedKeyHolder

update

public int update(String sql,
                  SqlParameterSource paramSource,
                  KeyHolder generatedKeyHolder,
                  String[] keyColumnNames)
           throws DataAccessException
Description copied from interface: NamedParameterJdbcOperations
Issue an update via a prepared statement, binding the given arguments, returning generated keys.

Specified by:
update in interface NamedParameterJdbcOperations
Parameters:
sql - SQL containing named parameters
paramSource - container of arguments and SQL types to bind to the query
generatedKeyHolder - KeyHolder that will hold the generated keys
keyColumnNames - names of the columns that will have keys generated for them
Returns:
the number of rows affected
Throws:
DataAccessException - if there is any problem issuing the update
See Also:
MapSqlParameterSource, GeneratedKeyHolder

getPreparedStatementCreator

protected PreparedStatementCreator getPreparedStatementCreator(String sql,
                                                               SqlParameterSource paramSource)
Build a PreparedStatementCreator based on the given SQL and named parameters.

Note: Not used for the update variant with generated key handling.

Parameters:
sql - SQL to execute
paramSource - container of arguments to bind
Returns:
the corresponding PreparedStatementCreator

getParsedSql

protected ParsedSql getParsedSql(String sql)
Obtain a parsed representation of the given SQL statement.

Parameters:
sql - the original SQL
Returns:
a representation of the parsed SQL statement

The Spring Framework

Copyright © 2002-2007 The Spring Framework.