java.lang.Object | ||
↳ | org.springframework.jdbc.support.JdbcAccessor | |
↳ | org.springframework.jdbc.core.JdbcTemplate |
This is the central class in the JDBC core package.
It simplifies the use of JDBC and helps to avoid common errors.
It executes core JDBC workflow, leaving application code to provide SQL
and extract results. This class executes SQL queries or updates, initiating
iteration over ResultSets and catching JDBC exceptions and translating
them to the generic, more informative exception hierarchy defined in the
org.springframework.dao
package.
Code using this class need only implement callback interfaces, giving
them a clearly defined contract. The PreparedStatementCreator
callback
interface creates a prepared statement given a Connection, providing SQL and
any necessary parameters. The ResultSetExtractor
interface extracts
values from a ResultSet. See also PreparedStatementSetter
and
RowMapper
for two popular alternative callback interfaces.
Can be used within a service implementation via direct instantiation with a DataSource reference, or get prepared in an application context and given to services as bean reference. Note: The DataSource should always be configured as a bean in the application context, in the first case given to the service directly, in the second case to the prepared template.
Because this class is parameterizable by the callback interfaces and
the SQLExceptionTranslator
interface, there should be no need to subclass it.
All SQL operations performed by this class are logged at debug level, using "org.springframework.jdbc.core.JdbcTemplate" as log category.
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Construct a new JdbcTemplate for bean usage.
| |||||||||||
Construct a new JdbcTemplate, given a DataSource to obtain connections from.
| |||||||||||
Construct a new JdbcTemplate, given a DataSource to obtain connections from.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Issue multiple SQL updates on a single JDBC Statement using batching.
| |||||||||||
Issue multiple update statements on a single PreparedStatement,
using batch updates and a BatchPreparedStatementSetter to set values.
| |||||||||||
Execute a SQL call using a CallableStatementCreator to provide SQL and any
required parameters.
| |||||||||||
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 Connection.
| |||||||||||
Execute a JDBC data access operation, implemented as callback action
working on a JDBC PreparedStatement.
| |||||||||||
Issue a single SQL execute, typically a DDL statement.
| |||||||||||
Execute a JDBC data access operation, implemented as callback action
working on a JDBC Statement.
| |||||||||||
Execute a JDBC data access operation, implemented as callback action
working on a JDBC CallableStatement.
| |||||||||||
Execute a JDBC data access operation, implemented as callback action
working on a JDBC CallableStatement.
| |||||||||||
Return the fetch size specified for this JdbcTemplate.
| |||||||||||
Return the maximum number of rows specified for this JdbcTemplate.
| |||||||||||
Return the current NativeJdbcExtractor implementation.
| |||||||||||
Return the query timeout for statements that this JdbcTemplate executes.
| |||||||||||
Return whether or not we ignore SQLWarnings.
| |||||||||||
Return whether execution of a CallableStatement will return the results in a Map
that uses case insensitive names for the parameters.
| |||||||||||
Return whether results processing should be skipped.
| |||||||||||
Return whether undeclared results should be skipped.
| |||||||||||
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 using a prepared statement, allowing for a PreparedStatementCreator
and a PreparedStatementSetter.
| |||||||||||
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 with a
ResultSetExtractor.
| |||||||||||
Query using a prepared statement, 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 using a prepared statement, mapping each row to a Java object
via a RowMapper.
| |||||||||||
Query given SQL to create a prepared statement from SQL and a
PreparedStatementSetter implementation that knows how to bind values
to the query, mapping each row to a Java object via a RowMapper.
| |||||||||||
Execute a query given static SQL, reading the ResultSet on a per-row
basis with a RowCallbackHandler.
| |||||||||||
Execute a query given static SQL, 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 using a prepared statement, reading the ResultSet on a per-row
basis with a RowCallbackHandler.
| |||||||||||
Query given SQL to create a prepared statement from SQL and a
PreparedStatementSetter implementation that knows how to bind values
to the query, reading the ResultSet on a per-row basis with a
RowCallbackHandler.
| |||||||||||
Execute a query given static SQL, 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 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, 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 using a prepared statement, 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, resulting in an int value.
| |||||||||||
Execute a query that results in an int value, given static SQL.
| |||||||||||
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.
| |||||||||||
Execute a query for a result list, given static SQL.
| |||||||||||
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result list.
| |||||||||||
Execute a query for a result list, given static SQL.
| |||||||||||
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.
| |||||||||||
Execute a query that results in a long value, given static SQL.
| |||||||||||
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.
| |||||||||||
Execute a query for a result Map, given static SQL.
| |||||||||||
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.
| |||||||||||
Execute a query given static SQL, 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, 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.
| |||||||||||
Execute a query for a result object, given static SQL.
| |||||||||||
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.
| |||||||||||
Execute a query for a SqlRowSet, given static SQL.
| |||||||||||
Set the fetch size for this JdbcTemplate.
| |||||||||||
Set whether or not we want to ignore SQLWarnings.
| |||||||||||
Set the maximum number of rows for this JdbcTemplate.
| |||||||||||
Set a NativeJdbcExtractor to extract native JDBC objects from wrapped handles.
| |||||||||||
Set the query timeout for statements that this JdbcTemplate executes.
| |||||||||||
Set whether execution of a CallableStatement will return the results in a Map
that uses case insensitive names for the parameters.
| |||||||||||
Set whether results processing should be skipped.
| |||||||||||
Set whether undelared results should be skipped.
| |||||||||||
Issue a single SQL update operation (such as an insert, update or delete statement).
| |||||||||||
Issue an update statement using a PreparedStatementSetter to set bind parameters,
with given SQL.
| |||||||||||
Issue a single SQL update operation (such as an insert, update or delete statement)
using a PreparedStatementCreator to provide SQL and any required parameters.
| |||||||||||
Issue a single SQL update operation (such as an insert, update or delete statement)
via a prepared statement, binding the given arguments.
| |||||||||||
Issue an update statement using a PreparedStatementCreator to provide SQL and
any required parameters.
| |||||||||||
Issue a single SQL update operation (such as an insert, update or delete statement)
via a prepared statement, binding the given arguments.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Prepare the given JDBC Statement (or PreparedStatement or CallableStatement),
applying statement settings such as fetch size, max rows, and query timeout.
| |||||||||||
Create a close-suppressing proxy for the given JDBC Connection.
| |||||||||||
Create a Map instance to be used as results map.
| |||||||||||
Extract output parameters from the completed stored procedure.
| |||||||||||
Extract returned ResultSets from the completed stored procedure.
| |||||||||||
Create a new RowMapper for reading columns as key-value pairs.
| |||||||||||
Create a new RowMapper for reading result objects from a single column.
| |||||||||||
Throw an SQLWarningException if encountering an actual warning.
| |||||||||||
Throw an SQLWarningException if we're not ignoring warnings,
else log the warnings (at debug level).
| |||||||||||
Create a new ArgPreparedStatementSetter using the args passed in.
| |||||||||||
Create a new ArgTypePreparedStatementSetter using the args and argTypes passed in.
| |||||||||||
Process the given ResultSet from a stored procedure.
| |||||||||||
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() |
Construct a new JdbcTemplate for bean usage.
Note: The DataSource has to be set before using the instance.
Construct a new JdbcTemplate, given a DataSource to obtain connections from.
Note: This will not trigger initialization of the exception translator.
dataSource | the JDBC DataSource to obtain connections from |
---|
Construct a new JdbcTemplate, given a DataSource to obtain connections from.
Note: Depending on the "lazyInit" flag, initialization of the exception translator will be triggered.
dataSource | the JDBC DataSource to obtain connections from |
---|---|
lazyInit | whether to lazily initialize the SQLExceptionTranslator |
Issue multiple SQL updates on a single JDBC Statement using batching.
Will fall back to separate updates on a single Statement if the JDBC driver does not support batch updates.
sql | defining an array of SQL statements that will be executed. |
---|
DataAccessException |
---|
Issue multiple update statements on a single PreparedStatement, using batch updates and a BatchPreparedStatementSetter to set values.
Will fall back to separate updates on a single PreparedStatement if the JDBC driver does not support batch updates.
sql | defining PreparedStatement that will be reused. All statements in the batch will use the same SQL. |
---|---|
pss | object to set parameters on the PreparedStatement created by this method |
DataAccessException |
---|
Execute a SQL call using a CallableStatementCreator to provide SQL and any required parameters.
csc | object that provides SQL and any necessary parameters |
---|---|
declaredParameters | list of declared SqlParameter objects |
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.
psc | object that can create a PreparedStatement given a Connection |
---|---|
action | callback object that specifies the action |
null
DataAccessException |
---|
Execute a JDBC data access operation, implemented as callback action working on a JDBC Connection. This allows for implementing arbitrary data access operations, 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.
action | the 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 |
---|---|
action | callback object that specifies the action |
null
DataAccessException |
---|
Issue a single SQL execute, typically a DDL statement.
sql | static SQL to execute |
---|
DataAccessException |
---|
Execute a JDBC data access operation, implemented as callback action working on a JDBC Statement. 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.
action | callback object that specifies the action |
---|
null
DataAccessException |
---|
Execute a JDBC data access operation, implemented as callback action working on a JDBC CallableStatement. 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.
csc | object that can create a CallableStatement given a Connection |
---|---|
action | callback object that specifies the action |
null
DataAccessException |
---|
Execute a JDBC data access operation, implemented as callback action working on a JDBC CallableStatement. 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.
callString | the SQL call string to execute |
---|---|
action | callback object that specifies the action |
null
DataAccessException |
---|
Return the fetch size specified for this JdbcTemplate.
Return the maximum number of rows specified for this JdbcTemplate.
Return the current NativeJdbcExtractor implementation.
Return the query timeout for statements that this JdbcTemplate executes.
Return whether or not we ignore SQLWarnings.
Return whether execution of a CallableStatement will return the results in a Map that uses case insensitive names for the parameters.
Return whether results processing should be skipped.
Return whether undeclared results should be skipped.
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 |
---|---|
args | arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scale |
rse | object that will extract results |
DataAccessException |
---|
Query using a prepared statement, allowing for a PreparedStatementCreator and a PreparedStatementSetter. Most other query methods use this method, but application code will always work with either a creator or a setter.
psc | Callback handler that can create a PreparedStatement given a Connection |
---|---|
pss | object that knows how to set values on the prepared statement. If this is null, the SQL will be assumed to contain no bind parameters. |
rse | object that will extract results. |
DataAccessException | if there is any problem |
---|
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 |
---|---|
rse | object that will extract results |
args | arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scale |
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 |
---|---|
args | arguments to bind to the query |
argTypes | SQL types of the arguments
(constants from java.sql.Types ) |
rse | object that will extract results |
DataAccessException |
---|
Query using a prepared statement, reading the ResultSet with a ResultSetExtractor.
A PreparedStatementCreator can either be implemented directly or configured through a PreparedStatementCreatorFactory.
psc | object that can create a PreparedStatement given a Connection |
---|---|
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 |
---|---|
args | arguments to bind to the query |
argTypes | SQL types of the arguments
(constants from java.sql.Types ) |
rch | object that will extract results, one row at a time |
DataAccessException |
---|
Query using a prepared statement, mapping each row to a Java object via a RowMapper.
A PreparedStatementCreator can either be implemented directly or configured through a PreparedStatementCreatorFactory.
psc | object that can create a PreparedStatement given a Connection |
---|---|
rowMapper | object that will map one object per row |
DataAccessException |
---|
Query given SQL to create a prepared statement from SQL and a PreparedStatementSetter implementation that knows how to bind values to the query, mapping each row to a Java object via a RowMapper.
sql | SQL query to execute |
---|---|
pss | object that knows how to set values on the prepared statement.
If this is null , the SQL will be assumed to contain no bind parameters.
Even if there are no bind parameters, this object may be used to
set fetch size and other performance options. |
rowMapper | object that will map one object per row |
DataAccessException |
---|
Execute a query given static SQL, reading the ResultSet on a per-row basis with a RowCallbackHandler.
Uses a JDBC Statement, not a PreparedStatement. If you want to
execute a static query with a PreparedStatement, use the overloaded
query
method with null
as argument array.
sql | SQL query to execute |
---|---|
rch | object that will extract results, one row at a time |
DataAccessException |
---|
Execute a query given static SQL, reading the ResultSet with a ResultSetExtractor.
Uses a JDBC Statement, not a PreparedStatement. If you want to
execute a static query with a PreparedStatement, use the overloaded
query
method with null
as argument array.
sql | SQL query to execute |
---|---|
rse | object that will extract all rows of 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 |
---|---|
rowMapper | object that will map one object per row |
args | arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scale |
DataAccessException |
---|
Query using a prepared statement, reading the ResultSet on a per-row basis with a RowCallbackHandler.
A PreparedStatementCreator can either be implemented directly or configured through a PreparedStatementCreatorFactory.
psc | object that can create a PreparedStatement given a Connection |
---|---|
rch | object that will extract results, one row at a time |
DataAccessException |
---|
Query given SQL to create a prepared statement from SQL and a PreparedStatementSetter implementation that knows how to bind values to the query, reading the ResultSet on a per-row basis with a RowCallbackHandler.
sql | SQL query to execute |
---|---|
pss | object that knows how to set values on the prepared statement.
If this is null , the SQL will be assumed to contain no bind parameters.
Even if there are no bind parameters, this object may be used to
set fetch size and other performance options. |
rch | object that will extract results, one row at a time |
DataAccessException |
---|
Execute a query given static SQL, mapping each row to a Java object via a RowMapper.
Uses a JDBC Statement, not a PreparedStatement. If you want to
execute a static query with a PreparedStatement, use the overloaded
query
method with null
as argument array.
sql | SQL query to execute |
---|---|
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 on a per-row basis with a RowCallbackHandler.
sql | SQL query to execute |
---|---|
rch | object that will extract results, one row at a time |
args | arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scale |
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 |
---|---|
args | arguments to bind to the query |
argTypes | SQL types of the arguments
(constants from java.sql.Types ) |
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 |
---|---|
args | arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scale |
rowMapper | object that will map one object per row |
DataAccessException |
---|
Query using a prepared statement, reading the ResultSet with a ResultSetExtractor.
sql | SQL query to execute |
---|---|
pss | object that knows how to set values on the prepared statement.
If this is null , the SQL will be assumed to contain no bind parameters.
Even if there are no bind parameters, this object may be used to
set fetch size and other performance options. |
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 |
---|---|
args | arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scale |
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 |
---|---|
args | arguments to bind to the query |
argTypes | SQL types of the arguments
(constants from java.sql.Types ) |
DataAccessException |
---|
Execute a query that results in an int value, given static SQL.
Uses a JDBC Statement, not a PreparedStatement. If you want to
execute a static query with a PreparedStatement, use the overloaded
queryForInt
method with null
as argument array.
This method is useful for running static SQL with a known outcome. The query is expected to be a single row/single column query that results in an int value.
sql | SQL query to execute |
---|
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 |
---|---|
args | arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scale |
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 |
---|---|
elementType | the required type of element in the result list
(for example, Integer.class ) |
args | arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scale |
DataAccessException |
---|
Execute a query for a result list, given static SQL.
Uses a JDBC Statement, not a PreparedStatement. If you want to
execute a static query with a PreparedStatement, use the overloaded
queryForList
method with null
as argument array.
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 |
---|
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 |
---|---|
args | arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scale |
elementType | the required type of element in the result list
(for example, Integer.class ) |
DataAccessException |
---|
Execute a query for a result list, given static SQL.
Uses a JDBC Statement, not a PreparedStatement. If you want to
execute a static query with a PreparedStatement, use the overloaded
queryForList
method with null
as argument array.
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 |
---|---|
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 |
---|---|
args | arguments to bind to the query |
argTypes | SQL types of the arguments
(constants from java.sql.Types ) |
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 |
---|---|
args | arguments to bind to the query |
argTypes | SQL types of the arguments
(constants from java.sql.Types ) |
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). Each element in the list will be of the form returned by this interface's queryForMap() methods.
sql | SQL query to execute |
---|---|
args | arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scale |
DataAccessException |
---|
Execute a query that results in a long value, given static SQL.
Uses a JDBC Statement, not a PreparedStatement. If you want to
execute a static query with a PreparedStatement, use the overloaded
queryForLong
method with null
as argument array.
This method is useful for running static SQL with a known outcome. The query is expected to be a single row/single column query that results in a long value.
sql | SQL query to execute |
---|
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 |
---|---|
args | arguments to bind to the query |
argTypes | SQL types of the arguments
(constants from java.sql.Types ) |
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 |
---|---|
args | arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scale |
DataAccessException |
---|
Execute a query for a result Map, given static SQL.
Uses a JDBC Statement, not a PreparedStatement. If you want to
execute a static query with a PreparedStatement, use the overloaded
queryForMap
method with null
as argument array.
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 |
---|
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 |
---|---|
args | arguments to bind to the query |
argTypes | SQL types of the arguments
(constants from java.sql.Types ) |
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 |
---|---|
args | arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scale |
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 |
---|---|
rowMapper | object that will map one object per row |
args | arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scale |
DataAccessException |
---|
Execute a query given static SQL, mapping a single result row to a Java object via a RowMapper.
Uses a JDBC Statement, not a PreparedStatement. If you want to
execute a static query with a PreparedStatement, use the overloaded
queryForObject
method with null
as argument array.
sql | SQL query to execute |
---|---|
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 |
---|---|
args | arguments to bind to the query |
argTypes | SQL types of the arguments
(constants from java.sql.Types ) |
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 |
---|---|
requiredType | the type that the result object is expected to match |
args | arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scale |
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 |
---|---|
args | arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scale |
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 |
---|---|
args | arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type) |
argTypes | SQL types of the arguments
(constants from java.sql.Types ) |
rowMapper | object that will map one object per row |
DataAccessException |
---|
Execute a query for a result object, given static SQL.
Uses a JDBC Statement, not a PreparedStatement. If you want to
execute a static query with a PreparedStatement, use the overloaded
queryForObject
method with null
as argument array.
This method is useful for running static SQL with a known outcome. 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 |
---|---|
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 |
---|---|
args | arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scale |
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 |
---|---|
args | arguments to bind to the query |
argTypes | SQL types of the arguments
(constants from java.sql.Types ) |
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 |
---|---|
args | arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scale |
javax.sql.rowset.CachedRowSet
)DataAccessException |
---|
Execute a query for a SqlRowSet, given static SQL.
Uses a JDBC Statement, not a PreparedStatement. If you want to
execute a static query with a PreparedStatement, use the overloaded
queryForRowSet
method with null
as argument array.
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 |
---|
javax.sql.rowset.CachedRowSet
)DataAccessException |
---|
Set the fetch size for this JdbcTemplate. This is important for processing large result sets: Setting this higher than the default value will increase processing speed at the cost of memory consumption; setting this lower can avoid transferring row data that will never be read by the application.
Default is 0, indicating to use the JDBC driver's default.
Set whether or not we want to ignore SQLWarnings.
Default is "true", swallowing and logging all warnings. Switch this flag to "false" to make the JdbcTemplate throw a SQLWarningException instead.
Set the maximum number of rows for this JdbcTemplate. This is important for processing subsets of large result sets, avoiding to read and hold the entire result set in the database or in the JDBC driver if we're never interested in the entire result in the first place (for example, when performing searches that might return a large number of matches).
Default is 0, indicating to use the JDBC driver's default.
Set a NativeJdbcExtractor to extract native JDBC objects from wrapped handles. Useful if native Statement and/or ResultSet handles are expected for casting to database-specific implementation classes, but a connection pool that wraps JDBC objects is used (note: any pool will return wrapped Connections).
Set the query timeout for statements that this JdbcTemplate executes.
Default is 0, indicating to use the JDBC driver's default.
Note: Any timeout specified here will be overridden by the remaining transaction timeout when executing within a transaction that has a timeout specified at the transaction level.
Set whether execution of a CallableStatement will return the results in a Map that uses case insensitive names for the parameters.
Set whether results processing should be skipped. Can be used to optimize callable statement processing when we know that no results are being passed back - the processing of out parameter will still take place. This can be used to avoid a bug in some older Oracle JDBC drivers like 10.1.0.2.
Set whether undelared results should be skipped.
Issue a single SQL update operation (such as an insert, update or delete statement).
sql | static SQL to execute |
---|
DataAccessException |
---|
Issue an update statement using a PreparedStatementSetter to set bind parameters, with given SQL. Simpler than using a PreparedStatementCreator as this method will create the PreparedStatement: The PreparedStatementSetter just needs to set parameters.
sql | SQL containing bind parameters |
---|---|
pss | helper that sets bind parameters. If this is null
we run an update with static SQL. |
DataAccessException |
---|
Issue a single SQL update operation (such as an insert, update or delete statement) using a PreparedStatementCreator to provide SQL and any required parameters.
A PreparedStatementCreator can either be implemented directly or configured through a PreparedStatementCreatorFactory.
psc | object that provides SQL and any necessary parameters |
---|
DataAccessException |
---|
Issue a single SQL update operation (such as an insert, update or delete statement) via a prepared statement, binding the given arguments.
sql | SQL containing bind parameters |
---|---|
args | arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scale |
DataAccessException |
---|
Issue an update statement using a PreparedStatementCreator to provide SQL and any required parameters. Generated keys will be put into the given KeyHolder.
Note that the given PreparedStatementCreator has to create a statement with activated extraction of generated keys (a JDBC 3.0 feature). This can either be done directly or through using a PreparedStatementCreatorFactory.
psc | object that provides SQL and any necessary parameters |
---|---|
generatedKeyHolder | KeyHolder that will hold the generated keys |
DataAccessException |
---|
Issue a single SQL update operation (such as an insert, update or delete statement) via a prepared statement, binding the given arguments.
sql | SQL containing bind parameters |
---|---|
args | arguments to bind to the query |
argTypes | SQL types of the arguments
(constants from java.sql.Types ) |
DataAccessException |
---|
Prepare the given JDBC Statement (or PreparedStatement or CallableStatement), applying statement settings such as fetch size, max rows, and query timeout.
stmt | the JDBC Statement to prepare |
---|
SQLException | if thrown by JDBC API |
---|
Create a close-suppressing proxy for the given JDBC Connection.
Called by the execute
method.
The proxy also prepares returned JDBC Statements, applying statement settings such as fetch size, max rows, and query timeout.
con | the JDBC Connection to create a proxy for |
---|
Create a Map instance to be used as results map.
If "isResultsMapCaseInsensitive" has been set to true, a linked case-insensitive Map will be created.
Extract output parameters from the completed stored procedure.
cs | JDBC wrapper for the stored procedure |
---|---|
parameters | parameter list for the stored procedure |
SQLException |
---|
Extract returned ResultSets from the completed stored procedure.
cs | JDBC wrapper for the stored procedure |
---|---|
updateCountParameters | Parameter list of declared update count parameters for the stored procedure |
resultSetParameters | Parameter list of declared resturn resultSet parameters for the stored procedure |
SQLException |
---|
Create a new RowMapper for reading columns as key-value pairs.
Create a new RowMapper for reading result objects from a single column.
requiredType | the type that each result object is expected to match |
---|
Throw an SQLWarningException if encountering an actual warning.
warning | the warnings object from the current statement.
May be null , in which case this method does nothing. |
---|
SQLWarningException | in case of an actual warning to be raised |
---|
Throw an SQLWarningException if we're not ignoring warnings, else log the warnings (at debug level).
stmt | the current JDBC statement |
---|
SQLWarningException | if not ignoring warnings |
---|---|
SQLException |
Create a new ArgPreparedStatementSetter using the args passed in. This method allows the creation to be overridden by sub-classes.
args | object array woth arguments |
---|
Create a new ArgTypePreparedStatementSetter using the args and argTypes passed in. This method allows the creation to be overridden by sub-classes.
args | object array woth arguments |
---|---|
argTypes | int array of SQLTypes for arguments |
Process the given ResultSet from a stored procedure.
rs | the ResultSet to process |
---|---|
param | the corresponding stored procedure parameter |
SQLException |
---|
DataAccessException |
---|