Top Description Inners Fields Constructors Methods
org.springframework.jdbc.core

public Class JdbcTemplate

extends JdbcAccessor
implements JdbcOperations
Class Inheritance
All Implemented Interfaces
org.springframework.jdbc.core.JdbcOperations
Imports
java.lang.reflect.InvocationHandler, .InvocationTargetException, .Method, .Proxy, java.sql.BatchUpdateException, .CallableStatement, .Connection, .PreparedStatement, .ResultSet, .SQLException, .SQLWarning, .Statement, java.util.ArrayList, .Collection, .Collections, .LinkedHashMap, .List, .Map, .Spliterator, java.util.function.Consumer, java.util.stream.Stream, .StreamSupport, javax.sql.DataSource, org.springframework.dao.DataAccessException, .InvalidDataAccessApiUsageException, org.springframework.dao.support.DataAccessUtils, org.springframework.jdbc.InvalidResultSetAccessException, .SQLWarningException, .UncategorizedSQLException, org.springframework.jdbc.datasource.ConnectionProxy, .DataSourceUtils, org.springframework.jdbc.support.JdbcAccessor, .JdbcUtils, .KeyHolder, org.springframework.jdbc.support.rowset.SqlRowSet, org.springframework.lang.Nullable, org.springframework.util.Assert, .CollectionUtils, .LinkedCaseInsensitiveMap, .StringUtils

This is the central delegate in the JDBC core package. It can be used directly for many data access purposes, supporting any kind of JDBC operation. For a more focused and convenient facade on top of this, consider org.springframework.jdbc.core.simple.JdbcClient as of 6.1.

This class 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 common org.springframework.dao exception hierarchy.

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.

An instance of this template class is thread-safe once configured. 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 org.springframework.jdbc.support.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.

NOTE: As of 6.1, there is a unified JDBC access facade available in the form of org.springframework.jdbc.core.simple.JdbcClient. JdbcClient provides a fluent API style for common JDBC queries/updates with flexible use of indexed or named parameters. It delegates to a JdbcTemplate/NamedParameterJdbcTemplate for actual execution.

Authors
Rod Johnson, Juergen Hoeller, Thomas Risberg
Since
May 3, 2001
See Also
JdbcOperations, PreparedStatementCreator, PreparedStatementSetter, CallableStatementCreator, PreparedStatementCallback, CallableStatementCallback, ResultSetExtractor, RowCallbackHandler, RowMapper, org.springframework.jdbc.support.SQLExceptionTranslator, org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
JdbcTemplate.CloseSuppressingInvocationHandler

Invocation handler that suppresses close calls on JDBC Connections.

private static class
JdbcTemplate.ResultSetSpliterator<T>

Spliterator for queryForStream adaptation of a ResultSet to a Stream.

private static class
JdbcTemplate.RowCallbackHandlerResultSetExtractor

Adapter to enable use of a RowCallbackHandler inside a ResultSetExtractor.

private static class
JdbcTemplate.SimpleCallableStatementCreator

Simple adapter for CallableStatementCreator, allowing to use a plain SQL statement.

private static class
JdbcTemplate.SimplePreparedStatementCreator

Simple adapter for PreparedStatementCreator, allowing to use a plain SQL statement.

Field Summary

Modifier and TypeField and Description
private int
fetchSize

If this variable is set to a non-negative value, it will be used for setting the fetchSize property on statements used for query processing.

private boolean
ignoreWarnings

If this variable is false, we will throw exceptions on SQL warnings.

private int
maxRows

If this variable is set to a non-negative value, it will be used for setting the maxRows property on statements used for query processing.

private int
queryTimeout

If this variable is set to a non-negative value, it will be used for setting the queryTimeout property on statements used for query processing.

private boolean
resultsMapCaseInsensitive

If this variable is set to true then execution of a CallableStatement will return the results in a Map that uses case-insensitive names for the parameters.

private static final String
private static final String
private boolean
skipResultsProcessing

If this variable is set to true, then all results checking will be bypassed for any callable statement processing.

private boolean
skipUndeclaredResults

If this variable is set to true then all results from a stored procedure call that don't have a corresponding SqlOutParameter declaration will be bypassed.

Inherited from org.springframework.jdbc.support.JdbcAccessor:
logger

Constructor Summary

AccessConstructor and Description
public
JdbcTemplate()

Construct a new JdbcTemplate for bean usage.

public
JdbcTemplate(DataSource
the JDBC DataSource to obtain connections from
dataSource
)

Construct a new JdbcTemplate, given a DataSource to obtain connections from.

public
JdbcTemplate(DataSource
the JDBC DataSource to obtain connections from
dataSource
,
boolean
whether to lazily initialize the SQLExceptionTranslator
lazyInit
)

Construct a new JdbcTemplate, given a DataSource to obtain connections from.

Method Summary

Modifier and TypeMethod and Description
protected void
applyStatementSettings(Statement
the JDBC Statement to prepare
stmt
)

Prepare the given JDBC Statement (or PreparedStatement or CallableStatement), applying statement settings such as fetch size, max rows, and query timeout.

public int[]
batchUpdate(final String...
defining an array of SQL statements that will be executed.
sql
)

Implements org.springframework.jdbc.core.JdbcOperations.batchUpdate.

Issue multiple SQL updates on a single JDBC Statement using batching.
public int[]
batchUpdate(final PreparedStatementCreator
a callback that creates a PreparedStatement given a Connection
psc
,
final BatchPreparedStatementSetter
object to set parameters on the PreparedStatement created by this method
pss
,
final KeyHolder
a KeyHolder that will hold the generated keys
generatedKeyHolder
)

Implements org.springframework.jdbc.core.JdbcOperations.batchUpdate.

Issue multiple update statements on a single PreparedStatement, using batch updates and a BatchPreparedStatementSetter to set values.
public int[]
batchUpdate(String
defining PreparedStatement that will be reused. All statements in the batch will use the same SQL.
sql
,
final BatchPreparedStatementSetter
object to set parameters on the PreparedStatement created by this method
pss
)

Implements org.springframework.jdbc.core.JdbcOperations.batchUpdate.

Issue multiple update statements on a single PreparedStatement, using batch updates and a BatchPreparedStatementSetter to set values.
public int[]
batchUpdate(String
the SQL statement to execute
sql
,
List<Object[]>
the List of Object arrays containing the batch of arguments for the query
batchArgs
)

Implements org.springframework.jdbc.core.JdbcOperations.batchUpdate.

Execute a batch using the supplied SQL statement with the batch of supplied arguments.
public int[]
batchUpdate(String
the SQL statement to execute.
sql
,
List<Object[]>
the List of Object arrays containing the batch of arguments for the query
batchArgs
,
final int[]
the SQL types of the arguments (constants from java.sql.Types)
argTypes
)

Implements org.springframework.jdbc.core.JdbcOperations.batchUpdate.

Execute a batch using the supplied SQL statement with the batch of supplied arguments.
public <T> int[][]
batchUpdate(String
the SQL statement to execute.
sql
,
final Collection<T>
the List of Object arrays containing the batch of arguments for the query
batchArgs
,
final int
batch size
batchSize
,
final ParameterizedPreparedStatementSetter<T>
the ParameterizedPreparedStatementSetter to use
pss
)

Implements org.springframework.jdbc.core.JdbcOperations.batchUpdate.

Execute multiple batches using the supplied SQL statement with the collect of supplied arguments.
public Map<String, Object>
call(CallableStatementCreator
a callback that provides SQL and any necessary parameters
csc
,
List<SqlParameter>
list of declared SqlParameter objects
declaredParameters
)

Implements org.springframework.jdbc.core.JdbcOperations.call.

Execute an SQL call using a CallableStatementCreator to provide SQL and any required parameters.
protected Connection

Returns:

the Connection proxy
createConnectionProxy
(Connection
the JDBC Connection to create a proxy for
con
)

Create a close-suppressing proxy for the given JDBC Connection.

protected Map<String, Object>

Returns:

the results Map instance
createResultsMap
()

Create a Map instance to be used as the results map.

public <T> T
execute(ConnectionCallback<T>
a callback object that specifies the action
action
)

Implements org.springframework.jdbc.core.JdbcOperations.execute.

Execute a JDBC data access operation, implemented as callback action working on a JDBC Connection.
private <T> T
execute(StatementCallback<T> action, boolean closeResources)

public <T> T
execute(StatementCallback<T>
a callback that specifies the action
action
)

Implements org.springframework.jdbc.core.JdbcOperations.execute.

Execute a JDBC data access operation, implemented as callback action working on a JDBC Statement.
public void
execute(final String
static SQL to execute
sql
)

Implements org.springframework.jdbc.core.JdbcOperations.execute.

Issue a single SQL execute, typically a DDL statement.
private <T> T
execute(PreparedStatementCreator psc, PreparedStatementCallback<T> action, boolean closeResources)

public <T> T
execute(PreparedStatementCreator
a callback that creates a PreparedStatement given a Connection
psc
,
PreparedStatementCallback<T>
a callback that specifies the action
action
)

Implements org.springframework.jdbc.core.JdbcOperations.execute.

Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement.
public <T> T
execute(String
the SQL to execute
sql
,
PreparedStatementCallback<T>
a callback that specifies the action
action
)

Implements org.springframework.jdbc.core.JdbcOperations.execute.

Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement.
public <T> T
execute(CallableStatementCreator
a callback that creates a CallableStatement given a Connection
csc
,
CallableStatementCallback<T>
a callback that specifies the action
action
)

Implements org.springframework.jdbc.core.JdbcOperations.execute.

Execute a JDBC data access operation, implemented as callback action working on a JDBC CallableStatement.
public <T> T
execute(String
the SQL call string to execute
callString
,
CallableStatementCallback<T>
a callback that specifies the action
action
)

Implements org.springframework.jdbc.core.JdbcOperations.execute.

Execute a JDBC data access operation, implemented as callback action working on a JDBC CallableStatement.
protected Map<String, Object>

Returns:

a Map that contains returned results
extractOutputParameters
(CallableStatement
the JDBC wrapper for the stored procedure
cs
,
List<SqlParameter>
parameter list for the stored procedure
parameters
)

Extract output parameters from the completed stored procedure.

protected Map<String, Object>

Returns:

a Map that contains returned results
extractReturnedResults
(CallableStatement
a JDBC wrapper for the stored procedure
cs
,
List<SqlParameter>
the parameter list of declared update count parameters for the stored procedure
updateCountParameters
,
List<SqlParameter>
the parameter list of declared resultSet parameters for the stored procedure
resultSetParameters
,
int updateCount)

Extract returned ResultSets from the completed stored procedure.

protected RowMapper<Map<String, Object>>

Returns:

the RowMapper to use
getColumnMapRowMapper
()

Create a new RowMapper for reading columns as key-value pairs.

public int
getFetchSize()

Return the fetch size specified for this JdbcTemplate.

public int
getMaxRows()

Return the maximum number of rows specified for this JdbcTemplate.

private PreparedStatementCallback<int[]>
public int
getQueryTimeout()

Return the query timeout for statements that this JdbcTemplate executes.

protected <T> RowMapper<T>

Returns:

the RowMapper to use
getSingleColumnRowMapper
(Class<T>
the type that each result object is expected to match
requiredType
)

Create a new RowMapper for reading result objects from a single column.

private static String

Returns:

the SQL string, or null if not known
getSql
(Object
object which is potentially an SqlProvider
obj
)

Determine SQL from potential provider object.

protected void
handleWarnings(Statement
the current JDBC statement
stmt
,
SQLException
the primary exception after failed statement execution
ex
)

Handle warnings before propagating a primary SQLException from executing the given statement.

protected void
handleWarnings(Statement
the current JDBC statement
stmt
)

Handle the warnings for the given JDBC statement, if any.

protected void
handleWarnings(SQLWarning
the warnings object from the current statement. May be null, in which case this method does nothing.
warning
)

Throw a SQLWarningException if encountering an actual warning.

public boolean
isIgnoreWarnings()

Return whether we ignore SQLWarnings.

public boolean
isResultsMapCaseInsensitive()

Return whether execution of a CallableStatement will return the results in a Map that uses case-insensitive names for the parameters.

public boolean
isSkipResultsProcessing()

Return whether results processing should be skipped.

public boolean
isSkipUndeclaredResults()

Return whether undeclared results should be skipped.

protected PreparedStatementSetter

Returns:

the new PreparedStatementSetter to use
newArgPreparedStatementSetter
(Object[]
object array with arguments
args
)

Create a new arg-based PreparedStatementSetter using the args passed in.

By default, we'll create an ArgumentPreparedStatementSetter.

protected PreparedStatementSetter

Returns:

the new PreparedStatementSetter to use
newArgTypePreparedStatementSetter
(Object[]
object array with arguments
args
,
int[]
int array of SQLTypes for the associated arguments
argTypes
)

Create a new arg-type-based PreparedStatementSetter using the args and types passed in.

By default, we'll create an ArgumentTypePreparedStatementSetter.

protected Map<String, Object>

Returns:

a Map that contains returned results
processResultSet
(ResultSet
the ResultSet to process
rs
,
ResultSetSupportingSqlParameter
the corresponding stored procedure parameter
param
)

Process the given ResultSet from a stored procedure.

public <T> T
query(final String
the SQL query to execute
sql
,
final ResultSetExtractor<T>
a callback that will extract all rows of results
rse
)

Implements org.springframework.jdbc.core.JdbcOperations.query.

Execute a query given static SQL, reading the ResultSet with a ResultSetExtractor.
public void
query(String
the SQL query to execute
sql
,
RowCallbackHandler
a callback that will extract results, one row at a time
rch
)

Implements org.springframework.jdbc.core.JdbcOperations.query.

Execute a query given static SQL, reading the ResultSet on a per-row basis with a RowCallbackHandler.
public <T> List<T>
query(String
the SQL query to execute
sql
,
RowMapper<T>
a callback that will map one object per row
rowMapper
)

Implements org.springframework.jdbc.core.JdbcOperations.query.

Execute a query given static SQL, mapping each row to a result object via a RowMapper.
public <T> T

Returns:

an arbitrary result object, as returned by the ResultSetExtractor
query
(PreparedStatementCreator
a callback that creates a PreparedStatement given a Connection
psc
,
final PreparedStatementSetter
a callback that knows how to set values on the prepared statement. If this is null, the SQL will be assumed to contain no bind parameters.
pss
,
final ResultSetExtractor<T>
a callback that will extract results
rse
)

Query using a prepared statement, allowing for a PreparedStatementCreator and a PreparedStatementSetter.

public <T> T
query(PreparedStatementCreator
a callback that creates a PreparedStatement given a Connection
psc
,
ResultSetExtractor<T>
a callback that will extract results
rse
)

Implements org.springframework.jdbc.core.JdbcOperations.query.

Query using a prepared statement, reading the ResultSet with a ResultSetExtractor.
public <T> T
query(String
the SQL query to execute
sql
,
PreparedStatementSetter
a callback 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 callback may be used to set the fetch size and other performance options.
pss
,
ResultSetExtractor<T>
a callback that will extract results
rse
)

Implements org.springframework.jdbc.core.JdbcOperations.query.

Query using a prepared statement, reading the ResultSet with a ResultSetExtractor.
public <T> T
query(String
the SQL query to execute
sql
,
Object[]
arguments to bind to the query
args
,
int[]
the SQL types of the arguments (constants from java.sql.Types)
argTypes
,
ResultSetExtractor<T>
a callback that will extract results
rse
)

Implements org.springframework.jdbc.core.JdbcOperations.query.

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.
public <T> T
query(String
the SQL query to execute
sql
,
Object[]
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
args
,
ResultSetExtractor<T>
a callback that will extract results
rse
)

Implements org.springframework.jdbc.core.JdbcOperations.query.

Deprecated
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.
public <T> T
query(String
the SQL query to execute
sql
,
ResultSetExtractor<T>
a callback that will extract results
rse
,
Object...
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
args
)

Implements org.springframework.jdbc.core.JdbcOperations.query.

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.
public void
query(PreparedStatementCreator
a callback that creates a PreparedStatement given a Connection
psc
,
RowCallbackHandler
a callback that will extract results, one row at a time
rch
)

Implements org.springframework.jdbc.core.JdbcOperations.query.

Query using a prepared statement, reading the ResultSet on a per-row basis with a RowCallbackHandler.
public void
query(String
the SQL query to execute
sql
,
PreparedStatementSetter
a callback 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 callback may be used to set the fetch size and other performance options.
pss
,
RowCallbackHandler
a callback that will extract results, one row at a time
rch
)

Implements org.springframework.jdbc.core.JdbcOperations.query.

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.
public void
query(String
the SQL query to execute
sql
,
Object[]
arguments to bind to the query
args
,
int[]
the SQL types of the arguments (constants from java.sql.Types)
argTypes
,
RowCallbackHandler
a callback that will extract results, one row at a time
rch
)

Implements org.springframework.jdbc.core.JdbcOperations.query.

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.
public void
query(String
the SQL query to execute
sql
,
Object[]
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
args
,
RowCallbackHandler
a callback that will extract results, one row at a time
rch
)

Implements org.springframework.jdbc.core.JdbcOperations.query.

Deprecated
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.
public void
query(String
the SQL query to execute
sql
,
RowCallbackHandler
a callback that will extract results, one row at a time
rch
,
Object...
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
args
)

Implements org.springframework.jdbc.core.JdbcOperations.query.

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.
public <T> List<T>
query(PreparedStatementCreator
a callback that creates a PreparedStatement given a Connection
psc
,
RowMapper<T>
a callback that will map one object per row
rowMapper
)

Implements org.springframework.jdbc.core.JdbcOperations.query.

Query using a prepared statement, mapping each row to a result object via a RowMapper.
public <T> List<T>
query(String
the SQL query to execute
sql
,
PreparedStatementSetter
a callback 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 callback may be used to set the fetch size and other performance options.
pss
,
RowMapper<T>
a callback that will map one object per row
rowMapper
)

Implements org.springframework.jdbc.core.JdbcOperations.query.

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 result object via a RowMapper.
public <T> List<T>
query(String
the SQL query to execute
sql
,
Object[]
arguments to bind to the query
args
,
int[]
the SQL types of the arguments (constants from java.sql.Types)
argTypes
,
RowMapper<T>
a callback that will map one object per row
rowMapper
)

Implements org.springframework.jdbc.core.JdbcOperations.query.

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 result object via a RowMapper.
public <T> List<T>
query(String
the SQL query to execute
sql
,
Object[]
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
args
,
RowMapper<T>
a callback that will map one object per row
rowMapper
)

Implements org.springframework.jdbc.core.JdbcOperations.query.

Deprecated
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 result object via a RowMapper.
public <T> List<T>
query(String
the SQL query to execute
sql
,
RowMapper<T>
a callback that will map one object per row
rowMapper
,
Object...
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
args
)

Implements org.springframework.jdbc.core.JdbcOperations.query.

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 result object via a RowMapper.
public <T> List<T>
queryForList(String
the SQL query to execute
sql
,
Class<T>
the required type of element in the result list (for example, Integer.class)
elementType
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForList.

Execute a query for a result list, given static SQL.
public List<Map<String, Object>>
queryForList(String
the SQL query to execute
sql
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForList.

Execute a query for a result list, given static SQL.
public <T> List<T>
queryForList(String
the SQL query to execute
sql
,
Object[]
arguments to bind to the query
args
,
int[]
the SQL types of the arguments (constants from java.sql.Types)
argTypes
,
Class<T>
the required type of element in the result list (for example, Integer.class)
elementType
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForList.

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.
public <T> List<T>
queryForList(String
the SQL query to execute
sql
,
Object[]
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
args
,
Class<T>
the required type of element in the result list (for example, Integer.class)
elementType
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForList.

Deprecated
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.
public <T> List<T>
queryForList(String
the SQL query to execute
sql
,
Class<T>
the required type of element in the result list (for example, Integer.class)
elementType
,
Object...
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
args
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForList.

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.
public List<Map<String, Object>>
queryForList(String
the SQL query to execute
sql
,
Object[]
arguments to bind to the query
args
,
int[]
the SQL types of the arguments (constants from java.sql.Types)
argTypes
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForList.

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.
public List<Map<String, Object>>
queryForList(String
the SQL query to execute
sql
,
Object...
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
args
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForList.

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.
public Map<String, Object>
queryForMap(String
the SQL query to execute
sql
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForMap.

Execute a query for a result map, given static SQL.
public Map<String, Object>
queryForMap(String
the SQL query to execute
sql
,
Object[]
arguments to bind to the query
args
,
int[]
the SQL types of the arguments (constants from java.sql.Types)
argTypes
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForMap.

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result map.
public Map<String, Object>
queryForMap(String
the SQL query to execute
sql
,
Object...
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
args
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForMap.

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result map.
public <T> T
queryForObject(String
the SQL query to execute
sql
,
RowMapper<T>
a callback that will map one object per row
rowMapper
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForObject.

Execute a query given static SQL, mapping a single result row to a result object via a RowMapper.
public <T> T
queryForObject(String
the SQL query to execute
sql
,
Class<T>
the type that the result object is expected to match
requiredType
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForObject.

Execute a query for a result object, given static SQL.
public <T> T
queryForObject(String
the SQL query to execute
sql
,
Object[]
arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
args
,
int[]
the SQL types of the arguments (constants from java.sql.Types)
argTypes
,
RowMapper<T>
a callback that will map one object per row
rowMapper
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForObject.

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 result object via a RowMapper.
public <T> T
queryForObject(String
the SQL query to execute
sql
,
Object[]
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
args
,
RowMapper<T>
a callback that will map one object per row
rowMapper
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForObject.

Deprecated
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 result object via a RowMapper.
public <T> T
queryForObject(String
the SQL query to execute
sql
,
RowMapper<T>
a callback that will map one object per row
rowMapper
,
Object...
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
args
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForObject.

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 result object via a RowMapper.
public <T> T
queryForObject(String
the SQL query to execute
sql
,
Object[]
arguments to bind to the query
args
,
int[]
the SQL types of the arguments (constants from java.sql.Types)
argTypes
,
Class<T>
the type that the result object is expected to match
requiredType
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForObject.

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result object.
public <T> T
queryForObject(String
the SQL query to execute
sql
,
Object[]
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
args
,
Class<T>
the type that the result object is expected to match
requiredType
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForObject.

Deprecated
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result object.
public <T> T
queryForObject(String
the SQL query to execute
sql
,
Class<T>
the type that the result object is expected to match
requiredType
,
Object...
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
args
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForObject.

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result object.
public SqlRowSet
queryForRowSet(String
the SQL query to execute
sql
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForRowSet.

Execute a query for an SqlRowSet, given static SQL.
public SqlRowSet
queryForRowSet(String
the SQL query to execute
sql
,
Object[]
arguments to bind to the query
args
,
int[]
the SQL types of the arguments (constants from java.sql.Types)
argTypes
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForRowSet.

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting an SqlRowSet.
public SqlRowSet
queryForRowSet(String
the SQL query to execute
sql
,
Object...
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
args
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForRowSet.

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting an SqlRowSet.
public <T> Stream<T>
queryForStream(String
the SQL query to execute
sql
,
RowMapper<T>
a callback that will map one object per row
rowMapper
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForStream.

Execute a query given static SQL, mapping each row to a result object via a RowMapper, and turning it into an iterable and closeable Stream.
public <T> Stream<T>

Returns:

the result Stream, containing mapped objects, needing to be closed once fully processed (e.g. through a try-with-resources clause)
queryForStream
(PreparedStatementCreator
a callback that creates a PreparedStatement given a Connection
psc
,
PreparedStatementSetter
a callback that knows how to set values on the prepared statement. If this is null, the SQL will be assumed to contain no bind parameters.
pss
,
RowMapper<T>
a callback that will map one object per row
rowMapper
)

Query using a prepared statement, allowing for a PreparedStatementCreator and a PreparedStatementSetter.

public <T> Stream<T>
queryForStream(PreparedStatementCreator
a callback that creates a PreparedStatement given a Connection
psc
,
RowMapper<T>
a callback that will map one object per row
rowMapper
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForStream.

Query using a prepared statement, mapping each row to a result object via a RowMapper, and turning it into an iterable and closeable Stream.
public <T> Stream<T>
queryForStream(String
the SQL query to execute
sql
,
PreparedStatementSetter
a callback 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 callback may be used to set the fetch size and other performance options.
pss
,
RowMapper<T>
a callback that will map one object per row
rowMapper
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForStream.

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 result object via a RowMapper, and turning it into an iterable and closeable Stream.
public <T> Stream<T>
queryForStream(String
the SQL query to execute
sql
,
RowMapper<T>
a callback that will map one object per row
rowMapper
,
Object...
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
args
)

Implements org.springframework.jdbc.core.JdbcOperations.queryForStream.

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 result object via a RowMapper, and turning it into an iterable and closeable Stream.
private static <T> T
result(T result)

public void
setFetchSize(int fetchSize)

Set the fetch size for this JdbcTemplate.

public void
setIgnoreWarnings(boolean ignoreWarnings)

Set whether we want to ignore JDBC statement warnings (SQLWarning).

public void
setMaxRows(int maxRows)

Set the maximum number of rows for this JdbcTemplate.

public void
setQueryTimeout(int queryTimeout)

Set the query timeout for statements that this JdbcTemplate executes.

public void
setResultsMapCaseInsensitive(boolean resultsMapCaseInsensitive)

Set whether execution of a CallableStatement will return the results in a Map that uses case-insensitive names for the parameters.

public void
setSkipResultsProcessing(boolean skipResultsProcessing)

Set whether results processing should be skipped.

public void
setSkipUndeclaredResults(boolean skipUndeclaredResults)

Set whether undeclared results should be skipped.

private void
storeGeneratedKeys(KeyHolder generatedKeyHolder, PreparedStatement ps, int rowsExpected)

protected DataAccessException

Returns:

a DataAccessException wrapping the SQLException (never null)
translateException
(String
readable text describing the task being attempted
task
,
String
the SQL query or update that caused the problem (may be null)
sql
,
SQLException
the offending SQLException
ex
)

Translate the given SQLException into a generic DataAccessException.

public int
update(final String
static SQL to execute
sql
)

Implements org.springframework.jdbc.core.JdbcOperations.update.

Issue a single SQL update operation (such as an insert, update or delete statement).
protected int
public int
update(PreparedStatementCreator
a callback that provides SQL and any necessary parameters
psc
)

Implements org.springframework.jdbc.core.JdbcOperations.update.

Issue a single SQL update operation (such as an insert, update or delete statement) using a PreparedStatementCreator to provide SQL and any required parameters.
public int
update(final PreparedStatementCreator
a callback that provides SQL and any necessary parameters
psc
,
final KeyHolder
a KeyHolder that will hold the generated keys
generatedKeyHolder
)

Implements org.springframework.jdbc.core.JdbcOperations.update.

Issue an update statement using a PreparedStatementCreator to provide SQL and any required parameters.
public int
update(String
the SQL containing bind parameters
sql
,
PreparedStatementSetter
helper that sets bind parameters. If this is null we run an update with static SQL.
pss
)

Implements org.springframework.jdbc.core.JdbcOperations.update.

Issue an update statement using a PreparedStatementSetter to set bind parameters, with given SQL.
public int
update(String
the SQL containing bind parameters
sql
,
Object[]
arguments to bind to the query
args
,
int[]
the SQL types of the arguments (constants from java.sql.Types)
argTypes
)

Implements org.springframework.jdbc.core.JdbcOperations.update.

Issue a single SQL update operation (such as an insert, update or delete statement) via a prepared statement, binding the given arguments.
public int
update(String
the SQL containing bind parameters
sql
,
Object...
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
args
)

Implements org.springframework.jdbc.core.JdbcOperations.update.

Issue a single SQL update operation (such as an insert, update or delete statement) via a prepared statement, binding the given arguments.
private static int
Inherited from org.springframework.jdbc.support.JdbcAccessor:
afterPropertiesSetgetDataSourcegetExceptionTranslatorisLazyInitobtainDataSourcesetDatabaseProductNamesetDataSourcesetExceptionTranslatorsetLazyInit