java.lang.Object | |
↳ | org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate |
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.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | DEFAULT_CACHE_LIMIT | Default maximum number of entries for this template's SQL cache: 256 |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new NamedParameterJdbcTemplate for the given
DataSource . | |||||||||||
Create a new NamedParameterJdbcTemplate for the given classic
Spring
JdbcTemplate . |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Execute a batch using the supplied SQL statement with the batch of supplied arguments.
| |||||||||||
Executes a batch using the supplied SQL statement with the batch of supplied arguments.
| |||||||||||
Execute a JDBC data access operation, implemented as callback action
working on a JDBC PreparedStatement.
| |||||||||||
Execute a JDBC data access operation, implemented as callback action
working on a JDBC PreparedStatement.
| |||||||||||
Return the maximum number of entries for this template's SQL cache.
| |||||||||||
Expose the classic Spring JdbcTemplate to allow invocation of
less commonly used methods.
| |||||||||||
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 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 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 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 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 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 given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, resulting in an int value.
| |||||||||||
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.
| |||||||||||
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result list.
| |||||||||||
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result list.
| |||||||||||
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result list.
| |||||||||||
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result list.
| |||||||||||
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.
| |||||||||||
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.
| |||||||||||
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result Map.
| |||||||||||
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result Map.
| |||||||||||
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.
| |||||||||||
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result object.
| |||||||||||
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result object.
| |||||||||||
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.
| |||||||||||
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a SqlRowSet.
| |||||||||||
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a SqlRowSet.
| |||||||||||
Specify the maximum number of entries for this template's SQL cache.
| |||||||||||
Issue an update via a prepared statement, binding the given arguments,
returning generated keys.
| |||||||||||
Issue an update via a prepared statement, binding the given arguments.
| |||||||||||
Issue an update via a prepared statement, binding the given arguments.
| |||||||||||
Issue an update via a prepared statement, binding the given arguments,
returning generated keys.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Obtain a parsed representation of the given SQL statement.
| |||||||||||
Build a PreparedStatementCreator based on the given SQL and named parameters.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations
|
Default maximum number of entries for this template's SQL cache: 256
Create a new NamedParameterJdbcTemplate for the given DataSource
.
Creates a classic Spring JdbcTemplate
and wraps it.
dataSource | the JDBC DataSource to access |
---|
Create a new NamedParameterJdbcTemplate for the given classic
Spring JdbcTemplate
.
classicJdbcTemplate | the classic Spring JdbcTemplate to wrap |
---|
Execute a batch using the supplied SQL statement with the batch of supplied arguments.
sql | the SQL statement to execute |
---|---|
batchArgs | the array of SqlParameterSource containing the batch of arguments for the query |
Executes a batch using the supplied SQL statement with the batch of supplied arguments.
sql | the SQL statement to execute |
---|---|
batchValues | the array of Maps containing the batch of arguments for the query |
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.
sql | SQL to execute |
---|---|
paramSource | container of arguments to bind to the query |
action | callback object that specifies the action |
null
DataAccessException |
---|
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.
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 |
null
DataAccessException |
---|
Return the maximum number of entries for this template's SQL cache.
Expose the classic Spring JdbcTemplate to allow invocation of less commonly used methods.
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.
sql | SQL query to execute |
---|---|
paramSource | container of arguments to bind to the query |
rse | object that will extract results |
DataAccessException |
---|
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.
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 |
DataAccessException |
---|
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.
sql | SQL query to execute |
---|---|
paramSource | container of arguments to bind to the query |
rowMapper | object that will map one object per row |
DataAccessException |
---|
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.
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 |
DataAccessException |
---|
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.
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 |
DataAccessException |
---|
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.
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 |
DataAccessException |
---|
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.
sql | SQL query to execute |
---|---|
paramSource | container of arguments to bind to the query |
DataAccessException |
---|
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.
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) |
DataAccessException |
---|
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.
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 ) |
DataAccessException |
---|
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.
sql | SQL query to execute |
---|---|
paramSource | container of arguments to bind to the query |
DataAccessException |
---|
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.
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) |
DataAccessException |
---|
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.
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 ) |
DataAccessException |
---|
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.
sql | SQL query to execute |
---|---|
paramSource | container of arguments to bind to the query |
DataAccessException |
---|
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.
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) |
DataAccessException |
---|
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).
sql | SQL query to execute |
---|---|
paramSource | container of arguments to bind to the query |
DataAccessException |
---|
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).
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) |
DataAccessException |
---|
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.
sql | SQL query to execute |
---|---|
paramSource | container of arguments to bind to the query |
rowMapper | object that will map one object per row |
DataAccessException |
---|
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.
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 |
null
in case of SQL NULLDataAccessException |
---|
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.
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 |
null
in case of SQL NULLDataAccessException |
---|
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.
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 |
DataAccessException |
---|
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).
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) |
javax.sql.rowset.CachedRowSet
)DataAccessException |
---|
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).
sql | SQL query to execute |
---|---|
paramSource | container of arguments to bind to the query |
javax.sql.rowset.CachedRowSet
)DataAccessException |
---|
Specify the maximum number of entries for this template's SQL cache. Default is 256.
Issue an update via a prepared statement, binding the given arguments, returning generated keys.
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 |
DataAccessException |
---|
Issue an update via a prepared statement, binding the given arguments.
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) |
DataAccessException |
---|
Issue an update via a prepared statement, binding the given arguments.
sql | SQL containing named parameters |
---|---|
paramSource | container of arguments and SQL types to bind to the query |
DataAccessException |
---|
Issue an update via a prepared statement, binding the given arguments, returning generated keys.
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 |
DataAccessException |
---|
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 |
---|
Build a PreparedStatementCreator based on the given SQL and named parameters.
Note: Not used for the update
variant with generated key handling.
sql | SQL to execute |
---|---|
paramSource | container of arguments to bind |