public class JdbcTemplate extends JdbcAccessor implements JdbcOperations
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.
PreparedStatementCreator
,
PreparedStatementSetter
,
CallableStatementCreator
,
PreparedStatementCallback
,
CallableStatementCallback
,
ResultSetExtractor
,
RowCallbackHandler
,
RowMapper
,
SQLExceptionTranslator
Modifier and Type | Class and Description |
---|---|
private class |
JdbcTemplate.CloseSuppressingInvocationHandler
Invocation handler that suppresses close calls on JDBC Connections.
|
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.
|
Modifier and Type | Field and Description |
---|---|
private int |
fetchSize
If this variable is set to a non-zero 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-zero value, it will be used for setting the
maxRows property on statements used for query processing.
|
private NativeJdbcExtractor |
nativeJdbcExtractor
Custom NativeJdbcExtractor
|
private int |
queryTimeout
If this variable is set to a non-zero 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 if
Commons Collections is available on the classpath.
|
private static java.lang.String |
RETURN_RESULT_SET_PREFIX |
private static java.lang.String |
RETURN_UPDATE_COUNT_PREFIX |
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.
|
logger
Constructor and Description |
---|
JdbcTemplate()
Construct a new JdbcTemplate for bean usage.
|
JdbcTemplate(javax.sql.DataSource dataSource)
Construct a new JdbcTemplate, given a DataSource to obtain connections from.
|
JdbcTemplate(javax.sql.DataSource dataSource,
boolean lazyInit)
Construct a new JdbcTemplate, given a DataSource to obtain connections from.
|
Modifier and Type | Method and Description |
---|---|
protected void |
applyStatementSettings(java.sql.Statement stmt)
Prepare the given JDBC Statement (or PreparedStatement or CallableStatement),
applying statement settings such as fetch size, max rows, and query timeout.
|
int[] |
batchUpdate(java.lang.String[] sql)
Issue multiple SQL updates on a single JDBC Statement using batching.
|
int[] |
batchUpdate(java.lang.String sql,
BatchPreparedStatementSetter pss)
Issue multiple update statements on a single PreparedStatement,
using batch updates and a BatchPreparedStatementSetter to set values.
|
<T> int[][] |
batchUpdate(java.lang.String sql,
java.util.Collection<T> batchArgs,
int batchSize,
ParameterizedPreparedStatementSetter<T> pss)
Execute multiple batches using the supplied SQL statement with the collect of supplied arguments.
|
int[] |
batchUpdate(java.lang.String sql,
java.util.List<java.lang.Object[]> batchArgs)
Execute a batch using the supplied SQL statement with the batch of supplied arguments.
|
int[] |
batchUpdate(java.lang.String sql,
java.util.List<java.lang.Object[]> batchArgs,
int[] argTypes)
Execute a batch using the supplied SQL statement with the batch of supplied arguments.
|
java.util.Map<java.lang.String,java.lang.Object> |
call(CallableStatementCreator csc,
java.util.List<SqlParameter> declaredParameters)
Execute a SQL call using a CallableStatementCreator to provide SQL and any
required parameters.
|
protected java.sql.Connection |
createConnectionProxy(java.sql.Connection con)
Create a close-suppressing proxy for the given JDBC Connection.
|
protected java.util.Map<java.lang.String,java.lang.Object> |
createResultsMap()
Create a Map instance to be used as results map.
|
<T> T |
execute(CallableStatementCreator csc,
CallableStatementCallback<T> action)
Execute a JDBC data access operation, implemented as callback action
working on a JDBC CallableStatement.
|
<T> T |
execute(ConnectionCallback<T> action)
Execute a JDBC data access operation, implemented as callback action
working on a JDBC Connection.
|
<T> T |
execute(PreparedStatementCreator psc,
PreparedStatementCallback<T> action)
Execute a JDBC data access operation, implemented as callback action
working on a JDBC PreparedStatement.
|
<T> T |
execute(StatementCallback<T> action)
Execute a JDBC data access operation, implemented as callback action
working on a JDBC Statement.
|
void |
execute(java.lang.String sql)
Issue a single SQL execute, typically a DDL statement.
|
<T> T |
execute(java.lang.String callString,
CallableStatementCallback<T> action)
Execute a JDBC data access operation, implemented as callback action
working on a JDBC CallableStatement.
|
<T> T |
execute(java.lang.String sql,
PreparedStatementCallback<T> action)
Execute a JDBC data access operation, implemented as callback action
working on a JDBC PreparedStatement.
|
protected java.util.Map<java.lang.String,java.lang.Object> |
extractOutputParameters(java.sql.CallableStatement cs,
java.util.List<SqlParameter> parameters)
Extract output parameters from the completed stored procedure.
|
protected java.util.Map<java.lang.String,java.lang.Object> |
extractReturnedResults(java.sql.CallableStatement cs,
java.util.List updateCountParameters,
java.util.List resultSetParameters,
int updateCount)
Extract returned ResultSets from the completed stored procedure.
|
protected RowMapper<java.util.Map<java.lang.String,java.lang.Object>> |
getColumnMapRowMapper()
Create a new RowMapper for reading columns as key-value pairs.
|
int |
getFetchSize()
Return the fetch size specified for this JdbcTemplate.
|
int |
getMaxRows()
Return the maximum number of rows specified for this JdbcTemplate.
|
NativeJdbcExtractor |
getNativeJdbcExtractor()
Return the current NativeJdbcExtractor implementation.
|
int |
getQueryTimeout()
Return the query timeout for statements that this JdbcTemplate executes.
|
protected <T> RowMapper<T> |
getSingleColumnRowMapper(java.lang.Class<T> requiredType)
Create a new RowMapper for reading result objects from a single column.
|
private static java.lang.String |
getSql(java.lang.Object sqlProvider)
Determine SQL from potential provider object.
|
protected void |
handleWarnings(java.sql.SQLWarning warning)
Throw an SQLWarningException if encountering an actual warning.
|
protected void |
handleWarnings(java.sql.Statement stmt)
Throw an SQLWarningException if we're not ignoring warnings,
else log the warnings (at debug level).
|
boolean |
isIgnoreWarnings()
Return whether or not we ignore SQLWarnings.
|
boolean |
isResultsMapCaseInsensitive()
Return whether execution of a CallableStatement will return the results in a Map
that uses case insensitive names for the parameters.
|
boolean |
isSkipResultsProcessing()
Return whether results processing should be skipped.
|
boolean |
isSkipUndeclaredResults()
Return whether undeclared results should be skipped.
|
protected PreparedStatementSetter |
newArgPreparedStatementSetter(java.lang.Object[] args)
Create a new ArgPreparedStatementSetter using the args passed in.
|
protected PreparedStatementSetter |
newArgTypePreparedStatementSetter(java.lang.Object[] args,
int[] argTypes)
Create a new ArgTypePreparedStatementSetter using the args and argTypes passed in.
|
protected java.util.Map<java.lang.String,java.lang.Object> |
processResultSet(java.sql.ResultSet rs,
ResultSetSupportingSqlParameter param)
Process the given ResultSet from a stored procedure.
|
<T> T |
query(PreparedStatementCreator psc,
PreparedStatementSetter pss,
ResultSetExtractor<T> rse)
Query using a prepared statement, allowing for a PreparedStatementCreator
and a PreparedStatementSetter.
|
<T> T |
query(PreparedStatementCreator psc,
ResultSetExtractor<T> rse)
Query using a prepared statement, reading the ResultSet with a
ResultSetExtractor.
|
void |
query(PreparedStatementCreator psc,
RowCallbackHandler rch)
Query using a prepared statement, reading the ResultSet on a per-row
basis with a RowCallbackHandler.
|
<T> java.util.List<T> |
query(PreparedStatementCreator psc,
RowMapper<T> rowMapper)
Query using a prepared statement, mapping each row to a Java object
via a RowMapper.
|
<T> T |
query(java.lang.String sql,
java.lang.Object[] args,
int[] argTypes,
ResultSetExtractor<T> rse)
Query given SQL to create a prepared statement from SQL and a list
of arguments to bind to the query, reading the ResultSet with a
ResultSetExtractor.
|
void |
query(java.lang.String sql,
java.lang.Object[] args,
int[] argTypes,
RowCallbackHandler rch)
Query given SQL to create a prepared statement from SQL and a list of
arguments to bind to the query, reading the ResultSet on a per-row basis
with a RowCallbackHandler.
|
<T> java.util.List<T> |
query(java.lang.String sql,
java.lang.Object[] args,
int[] argTypes,
RowMapper<T> rowMapper)
Query given SQL to create a prepared statement from SQL and a list
of arguments to bind to the query, mapping each row to a Java object
via a RowMapper.
|
<T> T |
query(java.lang.String sql,
java.lang.Object[] args,
ResultSetExtractor<T> rse)
Query given SQL to create a prepared statement from SQL and a list
of arguments to bind to the query, reading the ResultSet with a
ResultSetExtractor.
|
void |
query(java.lang.String sql,
java.lang.Object[] args,
RowCallbackHandler rch)
Query given SQL to create a prepared statement from SQL and a list of
arguments to bind to the query, reading the ResultSet on a per-row basis
with a RowCallbackHandler.
|
<T> java.util.List<T> |
query(java.lang.String sql,
java.lang.Object[] args,
RowMapper<T> rowMapper)
Query given SQL to create a prepared statement from SQL and a list
of arguments to bind to the query, mapping each row to a Java object
via a RowMapper.
|
<T> T |
query(java.lang.String sql,
PreparedStatementSetter pss,
ResultSetExtractor<T> rse)
Query using a prepared statement, reading the ResultSet with a
ResultSetExtractor.
|
void |
query(java.lang.String sql,
PreparedStatementSetter pss,
RowCallbackHandler rch)
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.
|
<T> java.util.List<T> |
query(java.lang.String sql,
PreparedStatementSetter pss,
RowMapper<T> 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.
|
<T> T |
query(java.lang.String sql,
ResultSetExtractor<T> rse)
Execute a query given static SQL, reading the ResultSet with a
ResultSetExtractor.
|
<T> T |
query(java.lang.String sql,
ResultSetExtractor<T> rse,
java.lang.Object... args)
Query given SQL to create a prepared statement from SQL and a list
of arguments to bind to the query, reading the ResultSet with a
ResultSetExtractor.
|
void |
query(java.lang.String sql,
RowCallbackHandler rch)
Execute a query given static SQL, reading the ResultSet on a per-row
basis with a RowCallbackHandler.
|
void |
query(java.lang.String sql,
RowCallbackHandler rch,
java.lang.Object... args)
Query given SQL to create a prepared statement from SQL and a list of
arguments to bind to the query, reading the ResultSet on a per-row basis
with a RowCallbackHandler.
|
<T> java.util.List<T> |
query(java.lang.String sql,
RowMapper<T> rowMapper)
Execute a query given static SQL, mapping each row to a Java object
via a RowMapper.
|
<T> java.util.List<T> |
query(java.lang.String sql,
RowMapper<T> rowMapper,
java.lang.Object... args)
Query given SQL to create a prepared statement from SQL and a list
of arguments to bind to the query, mapping each row to a Java object
via a RowMapper.
|
int |
queryForInt(java.lang.String sql)
Execute a query that results in an int value, given static SQL.
|
int |
queryForInt(java.lang.String sql,
java.lang.Object... args)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, resulting in an int value.
|
int |
queryForInt(java.lang.String sql,
java.lang.Object[] args,
int[] argTypes)
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.
|
java.util.List<java.util.Map<java.lang.String,java.lang.Object>> |
queryForList(java.lang.String sql)
Execute a query for a result list, given static SQL.
|
<T> java.util.List<T> |
queryForList(java.lang.String sql,
java.lang.Class<T> elementType)
Execute a query for a result list, given static SQL.
|
<T> java.util.List<T> |
queryForList(java.lang.String sql,
java.lang.Class<T> elementType,
java.lang.Object... args)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result list.
|
java.util.List<java.util.Map<java.lang.String,java.lang.Object>> |
queryForList(java.lang.String sql,
java.lang.Object... args)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result list.
|
<T> java.util.List<T> |
queryForList(java.lang.String sql,
java.lang.Object[] args,
java.lang.Class<T> elementType)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result list.
|
java.util.List<java.util.Map<java.lang.String,java.lang.Object>> |
queryForList(java.lang.String sql,
java.lang.Object[] args,
int[] argTypes)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result list.
|
<T> java.util.List<T> |
queryForList(java.lang.String sql,
java.lang.Object[] args,
int[] argTypes,
java.lang.Class<T> elementType)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result list.
|
long |
queryForLong(java.lang.String sql)
Execute a query that results in a long value, given static SQL.
|
long |
queryForLong(java.lang.String sql,
java.lang.Object... args)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, resulting in a long value.
|
long |
queryForLong(java.lang.String sql,
java.lang.Object[] args,
int[] argTypes)
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.
|
java.util.Map<java.lang.String,java.lang.Object> |
queryForMap(java.lang.String sql)
Execute a query for a result Map, given static SQL.
|
java.util.Map<java.lang.String,java.lang.Object> |
queryForMap(java.lang.String sql,
java.lang.Object... args)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result Map.
|
java.util.Map<java.lang.String,java.lang.Object> |
queryForMap(java.lang.String sql,
java.lang.Object[] args,
int[] argTypes)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result Map.
|
<T> T |
queryForObject(java.lang.String sql,
java.lang.Class<T> requiredType)
Execute a query for a result object, given static SQL.
|
<T> T |
queryForObject(java.lang.String sql,
java.lang.Class<T> requiredType,
java.lang.Object... args)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result object.
|
<T> T |
queryForObject(java.lang.String sql,
java.lang.Object[] args,
java.lang.Class<T> requiredType)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result object.
|
<T> T |
queryForObject(java.lang.String sql,
java.lang.Object[] args,
int[] argTypes,
java.lang.Class<T> requiredType)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result object.
|
<T> T |
queryForObject(java.lang.String sql,
java.lang.Object[] args,
int[] argTypes,
RowMapper<T> rowMapper)
Query given SQL to create a prepared statement from SQL and a list
of arguments to bind to the query, mapping a single result row to a
Java object via a RowMapper.
|
<T> T |
queryForObject(java.lang.String sql,
java.lang.Object[] args,
RowMapper<T> rowMapper)
Query given SQL to create a prepared statement from SQL and a list
of arguments to bind to the query, mapping a single result row to a
Java object via a RowMapper.
|
<T> T |
queryForObject(java.lang.String sql,
RowMapper<T> rowMapper)
Execute a query given static SQL, mapping a single result row to a Java
object via a RowMapper.
|
<T> T |
queryForObject(java.lang.String sql,
RowMapper<T> rowMapper,
java.lang.Object... args)
Query given SQL to create a prepared statement from SQL and a list
of arguments to bind to the query, mapping a single result row to a
Java object via a RowMapper.
|
SqlRowSet |
queryForRowSet(java.lang.String sql)
Execute a query for a SqlRowSet, given static SQL.
|
SqlRowSet |
queryForRowSet(java.lang.String sql,
java.lang.Object... args)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a SqlRowSet.
|
SqlRowSet |
queryForRowSet(java.lang.String sql,
java.lang.Object[] args,
int[] argTypes)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a SqlRowSet.
|
void |
setFetchSize(int fetchSize)
Set the fetch size for this JdbcTemplate.
|
void |
setIgnoreWarnings(boolean ignoreWarnings)
Set whether or not we want to ignore SQLWarnings.
|
void |
setMaxRows(int maxRows)
Set the maximum number of rows for this JdbcTemplate.
|
void |
setNativeJdbcExtractor(NativeJdbcExtractor extractor)
Set a NativeJdbcExtractor to extract native JDBC objects from wrapped handles.
|
void |
setQueryTimeout(int queryTimeout)
Set the query timeout for statements that this JdbcTemplate executes.
|
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.
|
void |
setSkipResultsProcessing(boolean skipResultsProcessing)
Set whether results processing should be skipped.
|
void |
setSkipUndeclaredResults(boolean skipUndeclaredResults)
Set whether undelared results should be skipped.
|
int |
update(PreparedStatementCreator psc)
Issue a single SQL update operation (such as an insert, update or delete statement)
using a PreparedStatementCreator to provide SQL and any required parameters.
|
int |
update(PreparedStatementCreator psc,
KeyHolder generatedKeyHolder)
Issue an update statement using a PreparedStatementCreator to provide SQL and
any required parameters.
|
protected int |
update(PreparedStatementCreator psc,
PreparedStatementSetter pss) |
int |
update(java.lang.String sql)
Issue a single SQL update operation (such as an insert, update or delete statement).
|
int |
update(java.lang.String sql,
java.lang.Object... args)
Issue a single SQL update operation (such as an insert, update or delete statement)
via a prepared statement, binding the given arguments.
|
int |
update(java.lang.String sql,
java.lang.Object[] args,
int[] argTypes)
Issue a single SQL update operation (such as an insert, update or delete statement)
via a prepared statement, binding the given arguments.
|
int |
update(java.lang.String sql,
PreparedStatementSetter pss)
Issue an update statement using a PreparedStatementSetter to set bind parameters,
with given SQL.
|
afterPropertiesSet, getDataSource, getExceptionTranslator, isLazyInit, setDatabaseProductName, setDataSource, setExceptionTranslator, setLazyInit
private static final java.lang.String RETURN_RESULT_SET_PREFIX
private static final java.lang.String RETURN_UPDATE_COUNT_PREFIX
private NativeJdbcExtractor nativeJdbcExtractor
private boolean ignoreWarnings
private int fetchSize
private int maxRows
private int queryTimeout
private boolean skipResultsProcessing
private boolean skipUndeclaredResults
skipResultsProcessing
is set to true
private boolean resultsMapCaseInsensitive
public JdbcTemplate()
Note: The DataSource has to be set before using the instance.
public JdbcTemplate(javax.sql.DataSource dataSource)
Note: This will not trigger initialization of the exception translator.
dataSource
- the JDBC DataSource to obtain connections frompublic JdbcTemplate(javax.sql.DataSource dataSource, boolean lazyInit)
Note: Depending on the "lazyInit" flag, initialization of the exception translator will be triggered.
dataSource
- the JDBC DataSource to obtain connections fromlazyInit
- whether to lazily initialize the SQLExceptionTranslatorpublic void setNativeJdbcExtractor(NativeJdbcExtractor extractor)
public NativeJdbcExtractor getNativeJdbcExtractor()
public void setIgnoreWarnings(boolean ignoreWarnings)
Default is "true", swallowing and logging all warnings. Switch this flag to "false" to make the JdbcTemplate throw a SQLWarningException instead.
SQLWarning
,
SQLWarningException
,
handleWarnings(java.sql.Statement)
public boolean isIgnoreWarnings()
public void setFetchSize(int fetchSize)
Default is 0, indicating to use the JDBC driver's default.
Statement.setFetchSize(int)
public int getFetchSize()
public void setMaxRows(int maxRows)
Default is 0, indicating to use the JDBC driver's default.
Statement.setMaxRows(int)
public int getMaxRows()
public void setQueryTimeout(int queryTimeout)
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.
Statement.setQueryTimeout(int)
public int getQueryTimeout()
public void setSkipResultsProcessing(boolean skipResultsProcessing)
public boolean isSkipResultsProcessing()
public void setSkipUndeclaredResults(boolean skipUndeclaredResults)
public boolean isSkipUndeclaredResults()
public void setResultsMapCaseInsensitive(boolean resultsMapCaseInsensitive)
public boolean isResultsMapCaseInsensitive()
public <T> T execute(ConnectionCallback<T> action) throws DataAccessException
JdbcOperations
The callback action can return a result object, for example a domain object or a collection of domain objects.
execute
in interface JdbcOperations
action
- the callback object that specifies the actionnull
DataAccessException
- if there is any problemprotected java.sql.Connection createConnectionProxy(java.sql.Connection con)
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 forConnection.close()
,
execute(ConnectionCallback)
,
applyStatementSettings(java.sql.Statement)
public <T> T execute(StatementCallback<T> action) throws DataAccessException
JdbcOperations
The callback action can return a result object, for example a domain object or a collection of domain objects.
execute
in interface JdbcOperations
action
- callback object that specifies the actionnull
DataAccessException
- if there is any problempublic void execute(java.lang.String sql) throws DataAccessException
JdbcOperations
execute
in interface JdbcOperations
sql
- static SQL to executeDataAccessException
- if there is any problempublic <T> T query(java.lang.String sql, ResultSetExtractor<T> rse) throws DataAccessException
JdbcOperations
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.
query
in interface JdbcOperations
sql
- SQL query to executerse
- object that will extract all rows of resultsDataAccessException
- if there is any problem executing the queryJdbcOperations.query(String, Object[], ResultSetExtractor)
public void query(java.lang.String sql, RowCallbackHandler rch) throws DataAccessException
JdbcOperations
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.
query
in interface JdbcOperations
sql
- SQL query to executerch
- object that will extract results, one row at a timeDataAccessException
- if there is any problem executing the queryJdbcOperations.query(String, Object[], RowCallbackHandler)
public <T> java.util.List<T> query(java.lang.String sql, RowMapper<T> rowMapper) throws DataAccessException
JdbcOperations
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.
query
in interface JdbcOperations
sql
- SQL query to executerowMapper
- object that will map one object per rowDataAccessException
- if there is any problem executing the queryJdbcOperations.query(String, Object[], RowMapper)
public java.util.Map<java.lang.String,java.lang.Object> queryForMap(java.lang.String sql) throws DataAccessException
JdbcOperations
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).
queryForMap
in interface JdbcOperations
sql
- SQL query to executeIncorrectResultSizeDataAccessException
- if the query does not
return exactly one rowDataAccessException
- if there is any problem executing the queryJdbcOperations.queryForMap(String, Object[])
,
ColumnMapRowMapper
public <T> T queryForObject(java.lang.String sql, RowMapper<T> rowMapper) throws DataAccessException
JdbcOperations
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.
queryForObject
in interface JdbcOperations
sql
- SQL query to executerowMapper
- object that will map one object per rowIncorrectResultSizeDataAccessException
- if the query does not
return exactly one rowDataAccessException
- if there is any problem executing the queryJdbcOperations.queryForObject(String, Object[], RowMapper)
public <T> T queryForObject(java.lang.String sql, java.lang.Class<T> requiredType) throws DataAccessException
JdbcOperations
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.
queryForObject
in interface JdbcOperations
sql
- SQL query to executerequiredType
- the type that the result object is expected to matchnull
in case of SQL NULLIncorrectResultSizeDataAccessException
- if the query does not return
exactly one row, or does not return exactly one column in that rowDataAccessException
- if there is any problem executing the queryJdbcOperations.queryForObject(String, Object[], Class)
public long queryForLong(java.lang.String sql) throws DataAccessException
JdbcOperations
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.
queryForLong
in interface JdbcOperations
sql
- SQL query to executeIncorrectResultSizeDataAccessException
- if the query does not return
exactly one row, or does not return exactly one column in that rowDataAccessException
- if there is any problem executing the queryJdbcOperations.queryForLong(String, Object[])
public int queryForInt(java.lang.String sql) throws DataAccessException
JdbcOperations
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.
queryForInt
in interface JdbcOperations
sql
- SQL query to executeIncorrectResultSizeDataAccessException
- if the query does not return
exactly one row, or does not return exactly one column in that rowDataAccessException
- if there is any problem executing the queryJdbcOperations.queryForInt(String, Object[])
public <T> java.util.List<T> queryForList(java.lang.String sql, java.lang.Class<T> elementType) throws DataAccessException
JdbcOperations
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.
queryForList
in interface JdbcOperations
sql
- SQL query to executeelementType
- the required type of element in the result list
(for example, Integer.class
)DataAccessException
- if there is any problem executing the queryJdbcOperations.queryForList(String, Object[], Class)
,
SingleColumnRowMapper
public java.util.List<java.util.Map<java.lang.String,java.lang.Object>> queryForList(java.lang.String sql) throws DataAccessException
JdbcOperations
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.
queryForList
in interface JdbcOperations
sql
- SQL query to executeDataAccessException
- if there is any problem executing the queryJdbcOperations.queryForList(String, Object[])
public SqlRowSet queryForRowSet(java.lang.String sql) throws DataAccessException
JdbcOperations
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).
queryForRowSet
in interface JdbcOperations
sql
- SQL query to executejavax.sql.rowset.CachedRowSet
)DataAccessException
- if there is any problem executing the queryJdbcOperations.queryForRowSet(String, Object[])
,
SqlRowSetResultSetExtractor
,
CachedRowSet
public int update(java.lang.String sql) throws DataAccessException
JdbcOperations
update
in interface JdbcOperations
sql
- static SQL to executeDataAccessException
- if there is any problem.public int[] batchUpdate(java.lang.String[] sql) throws DataAccessException
JdbcOperations
Will fall back to separate updates on a single Statement if the JDBC driver does not support batch updates.
batchUpdate
in interface JdbcOperations
sql
- defining an array of SQL statements that will be executed.DataAccessException
- if there is any problem executing the batchpublic <T> T execute(PreparedStatementCreator psc, PreparedStatementCallback<T> action) throws DataAccessException
JdbcOperations
The callback action can return a result object, for example a domain object or a collection of domain objects.
execute
in interface JdbcOperations
psc
- object that can create a PreparedStatement given a Connectionaction
- callback object that specifies the actionnull
DataAccessException
- if there is any problempublic <T> T execute(java.lang.String sql, PreparedStatementCallback<T> action) throws DataAccessException
JdbcOperations
The callback action can return a result object, for example a domain object or a collection of domain objects.
execute
in interface JdbcOperations
sql
- SQL to executeaction
- callback object that specifies the actionnull
DataAccessException
- if there is any problempublic <T> T query(PreparedStatementCreator psc, PreparedStatementSetter pss, ResultSetExtractor<T> rse) throws DataAccessException
psc
- Callback handler that can create a PreparedStatement given a
Connectionpss
- 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 problempublic <T> T query(PreparedStatementCreator psc, ResultSetExtractor<T> rse) throws DataAccessException
JdbcOperations
A PreparedStatementCreator can either be implemented directly or configured through a PreparedStatementCreatorFactory.
query
in interface JdbcOperations
psc
- object that can create a PreparedStatement given a Connectionrse
- object that will extract resultsDataAccessException
- if there is any problemPreparedStatementCreatorFactory
public <T> T query(java.lang.String sql, PreparedStatementSetter pss, ResultSetExtractor<T> rse) throws DataAccessException
JdbcOperations
query
in interface JdbcOperations
sql
- SQL query to executepss
- 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 resultsDataAccessException
- if there is any problempublic <T> T query(java.lang.String sql, java.lang.Object[] args, int[] argTypes, ResultSetExtractor<T> rse) throws DataAccessException
JdbcOperations
query
in interface JdbcOperations
sql
- SQL query to executeargs
- arguments to bind to the queryargTypes
- SQL types of the arguments
(constants from java.sql.Types
)rse
- object that will extract resultsDataAccessException
- if the query failsTypes
public <T> T query(java.lang.String sql, java.lang.Object[] args, ResultSetExtractor<T> rse) throws DataAccessException
JdbcOperations
query
in interface JdbcOperations
sql
- SQL query to executeargs
- 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 scalerse
- object that will extract resultsDataAccessException
- if the query failspublic <T> T query(java.lang.String sql, ResultSetExtractor<T> rse, java.lang.Object... args) throws DataAccessException
JdbcOperations
query
in interface JdbcOperations
sql
- SQL query to executerse
- object that will extract resultsargs
- 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 scaleDataAccessException
- if the query failspublic void query(PreparedStatementCreator psc, RowCallbackHandler rch) throws DataAccessException
JdbcOperations
A PreparedStatementCreator can either be implemented directly or configured through a PreparedStatementCreatorFactory.
query
in interface JdbcOperations
psc
- object that can create a PreparedStatement given a Connectionrch
- object that will extract results, one row at a timeDataAccessException
- if there is any problemPreparedStatementCreatorFactory
public void query(java.lang.String sql, PreparedStatementSetter pss, RowCallbackHandler rch) throws DataAccessException
JdbcOperations
query
in interface JdbcOperations
sql
- SQL query to executepss
- 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 timeDataAccessException
- if the query failspublic void query(java.lang.String sql, java.lang.Object[] args, int[] argTypes, RowCallbackHandler rch) throws DataAccessException
JdbcOperations
query
in interface JdbcOperations
sql
- SQL query to executeargs
- arguments to bind to the queryargTypes
- SQL types of the arguments
(constants from java.sql.Types
)rch
- object that will extract results, one row at a timeDataAccessException
- if the query failsTypes
public void query(java.lang.String sql, java.lang.Object[] args, RowCallbackHandler rch) throws DataAccessException
JdbcOperations
query
in interface JdbcOperations
sql
- SQL query to executeargs
- 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 scalerch
- object that will extract results, one row at a timeDataAccessException
- if the query failspublic void query(java.lang.String sql, RowCallbackHandler rch, java.lang.Object... args) throws DataAccessException
JdbcOperations
query
in interface JdbcOperations
sql
- SQL query to executerch
- object that will extract results, one row at a timeargs
- 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 scaleDataAccessException
- if the query failspublic <T> java.util.List<T> query(PreparedStatementCreator psc, RowMapper<T> rowMapper) throws DataAccessException
JdbcOperations
A PreparedStatementCreator can either be implemented directly or configured through a PreparedStatementCreatorFactory.
query
in interface JdbcOperations
psc
- object that can create a PreparedStatement given a ConnectionrowMapper
- object that will map one object per rowDataAccessException
- if there is any problemPreparedStatementCreatorFactory
public <T> java.util.List<T> query(java.lang.String sql, PreparedStatementSetter pss, RowMapper<T> rowMapper) throws DataAccessException
JdbcOperations
query
in interface JdbcOperations
sql
- SQL query to executepss
- 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 rowDataAccessException
- if the query failspublic <T> java.util.List<T> query(java.lang.String sql, java.lang.Object[] args, int[] argTypes, RowMapper<T> rowMapper) throws DataAccessException
JdbcOperations
query
in interface JdbcOperations
sql
- SQL query to executeargs
- arguments to bind to the queryargTypes
- SQL types of the arguments
(constants from java.sql.Types
)rowMapper
- object that will map one object per rowDataAccessException
- if the query failsTypes
public <T> java.util.List<T> query(java.lang.String sql, java.lang.Object[] args, RowMapper<T> rowMapper) throws DataAccessException
JdbcOperations
query
in interface JdbcOperations
sql
- SQL query to executeargs
- 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 scalerowMapper
- object that will map one object per rowDataAccessException
- if the query failspublic <T> java.util.List<T> query(java.lang.String sql, RowMapper<T> rowMapper, java.lang.Object... args) throws DataAccessException
JdbcOperations
query
in interface JdbcOperations
sql
- SQL query to executerowMapper
- object that will map one object per rowargs
- 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 scaleDataAccessException
- if the query failspublic <T> T queryForObject(java.lang.String sql, java.lang.Object[] args, int[] argTypes, RowMapper<T> rowMapper) throws DataAccessException
JdbcOperations
queryForObject
in interface JdbcOperations
sql
- SQL query to executeargs
- 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 rowIncorrectResultSizeDataAccessException
- if the query does not
return exactly one rowDataAccessException
- if the query failspublic <T> T queryForObject(java.lang.String sql, java.lang.Object[] args, RowMapper<T> rowMapper) throws DataAccessException
JdbcOperations
queryForObject
in interface JdbcOperations
sql
- SQL query to executeargs
- 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 scalerowMapper
- object that will map one object per rowIncorrectResultSizeDataAccessException
- if the query does not
return exactly one rowDataAccessException
- if the query failspublic <T> T queryForObject(java.lang.String sql, RowMapper<T> rowMapper, java.lang.Object... args) throws DataAccessException
JdbcOperations
queryForObject
in interface JdbcOperations
sql
- SQL query to executerowMapper
- object that will map one object per rowargs
- 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 scaleIncorrectResultSizeDataAccessException
- if the query does not
return exactly one rowDataAccessException
- if the query failspublic <T> T queryForObject(java.lang.String sql, java.lang.Object[] args, int[] argTypes, java.lang.Class<T> requiredType) throws DataAccessException
JdbcOperations
The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.
queryForObject
in interface JdbcOperations
sql
- SQL query to executeargs
- arguments to bind to the queryargTypes
- SQL types of the arguments
(constants from java.sql.Types
)requiredType
- the type that the result object is expected to matchnull
in case of SQL NULLIncorrectResultSizeDataAccessException
- if the query does not return
exactly one row, or does not return exactly one column in that rowDataAccessException
- if the query failsJdbcOperations.queryForObject(String, Class)
,
Types
public <T> T queryForObject(java.lang.String sql, java.lang.Object[] args, java.lang.Class<T> requiredType) throws DataAccessException
JdbcOperations
The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.
queryForObject
in interface JdbcOperations
sql
- SQL query to executeargs
- 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 scalerequiredType
- the type that the result object is expected to matchnull
in case of SQL NULLIncorrectResultSizeDataAccessException
- if the query does not return
exactly one row, or does not return exactly one column in that rowDataAccessException
- if the query failsJdbcOperations.queryForObject(String, Class)
public <T> T queryForObject(java.lang.String sql, java.lang.Class<T> requiredType, java.lang.Object... args) throws DataAccessException
JdbcOperations
The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.
queryForObject
in interface JdbcOperations
sql
- SQL query to executerequiredType
- the type that the result object is expected to matchargs
- 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 scalenull
in case of SQL NULLIncorrectResultSizeDataAccessException
- if the query does not return
exactly one row, or does not return exactly one column in that rowDataAccessException
- if the query failsJdbcOperations.queryForObject(String, Class)
public java.util.Map<java.lang.String,java.lang.Object> queryForMap(java.lang.String sql, java.lang.Object[] args, int[] argTypes) throws DataAccessException
JdbcOperations
The query is expected to be a single row query; the result row will be mapped to a Map (one entry for each column, using the column name as the key).
queryForMap
in interface JdbcOperations
sql
- SQL query to executeargs
- arguments to bind to the queryargTypes
- SQL types of the arguments
(constants from java.sql.Types
)IncorrectResultSizeDataAccessException
- if the query does not
return exactly one rowDataAccessException
- if the query failsJdbcOperations.queryForMap(String)
,
ColumnMapRowMapper
,
Types
public java.util.Map<java.lang.String,java.lang.Object> queryForMap(java.lang.String sql, java.lang.Object... args) throws DataAccessException
JdbcOperations
The query is expected to be a single row query; the result row will be mapped to a Map (one entry for each column, using the column name as the key).
queryForMap
in interface JdbcOperations
sql
- SQL query to executeargs
- 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 scaleIncorrectResultSizeDataAccessException
- if the query does not
return exactly one rowDataAccessException
- if the query failsJdbcOperations.queryForMap(String)
,
ColumnMapRowMapper
public long queryForLong(java.lang.String sql, java.lang.Object[] args, int[] argTypes) throws DataAccessException
JdbcOperations
The query is expected to be a single row/single column query that results in a long value.
queryForLong
in interface JdbcOperations
sql
- SQL query to executeargs
- arguments to bind to the queryargTypes
- SQL types of the arguments
(constants from java.sql.Types
)IncorrectResultSizeDataAccessException
- if the query does not return
exactly one row, or does not return exactly one column in that rowDataAccessException
- if the query failsJdbcOperations.queryForLong(String)
,
Types
public long queryForLong(java.lang.String sql, java.lang.Object... args) throws DataAccessException
JdbcOperations
The query is expected to be a single row/single column query that results in a long value.
queryForLong
in interface JdbcOperations
sql
- SQL query to executeargs
- 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 scaleIncorrectResultSizeDataAccessException
- if the query does not return
exactly one row, or does not return exactly one column in that rowDataAccessException
- if the query failsJdbcOperations.queryForLong(String)
public int queryForInt(java.lang.String sql, java.lang.Object[] args, int[] argTypes) throws DataAccessException
JdbcOperations
The query is expected to be a single row/single column query that results in an int value.
queryForInt
in interface JdbcOperations
sql
- SQL query to executeargs
- arguments to bind to the queryargTypes
- SQL types of the arguments
(constants from java.sql.Types
)IncorrectResultSizeDataAccessException
- if the query does not return
exactly one row, or does not return exactly one column in that rowDataAccessException
- if the query failsJdbcOperations.queryForInt(String)
,
Types
public int queryForInt(java.lang.String sql, java.lang.Object... args) throws DataAccessException
JdbcOperations
The query is expected to be a single row/single column query that results in an int value.
queryForInt
in interface JdbcOperations
sql
- SQL query to executeargs
- 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 scaleIncorrectResultSizeDataAccessException
- if the query does not return
exactly one row, or does not return exactly one column in that rowDataAccessException
- if the query failsJdbcOperations.queryForInt(String)
public <T> java.util.List<T> queryForList(java.lang.String sql, java.lang.Object[] args, int[] argTypes, java.lang.Class<T> elementType) throws DataAccessException
JdbcOperations
The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.
queryForList
in interface JdbcOperations
sql
- SQL query to executeargs
- arguments to bind to the queryargTypes
- 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
- if the query failsJdbcOperations.queryForList(String, Class)
,
SingleColumnRowMapper
public <T> java.util.List<T> queryForList(java.lang.String sql, java.lang.Object[] args, java.lang.Class<T> elementType) throws DataAccessException
JdbcOperations
The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.
queryForList
in interface JdbcOperations
sql
- SQL query to executeargs
- 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 scaleelementType
- the required type of element in the result list
(for example, Integer.class
)DataAccessException
- if the query failsJdbcOperations.queryForList(String, Class)
,
SingleColumnRowMapper
public <T> java.util.List<T> queryForList(java.lang.String sql, java.lang.Class<T> elementType, java.lang.Object... args) throws DataAccessException
JdbcOperations
The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.
queryForList
in interface JdbcOperations
sql
- SQL query to executeelementType
- 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 scaleDataAccessException
- if the query failsJdbcOperations.queryForList(String, Class)
,
SingleColumnRowMapper
public java.util.List<java.util.Map<java.lang.String,java.lang.Object>> queryForList(java.lang.String sql, java.lang.Object[] args, int[] argTypes) throws DataAccessException
JdbcOperations
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.
queryForList
in interface JdbcOperations
sql
- SQL query to executeargs
- arguments to bind to the queryargTypes
- SQL types of the arguments
(constants from java.sql.Types
)DataAccessException
- if the query failsJdbcOperations.queryForList(String)
,
Types
public java.util.List<java.util.Map<java.lang.String,java.lang.Object>> queryForList(java.lang.String sql, java.lang.Object... args) throws DataAccessException
JdbcOperations
The results will be mapped to a List (one entry for each row) of Maps (one entry for each column, using the column name as the key). Each element in the list will be of the form returned by this interface's queryForMap() methods.
queryForList
in interface JdbcOperations
sql
- SQL query to executeargs
- 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 scaleDataAccessException
- if the query failsJdbcOperations.queryForList(String)
public SqlRowSet queryForRowSet(java.lang.String sql, java.lang.Object[] args, int[] argTypes) throws DataAccessException
JdbcOperations
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).
queryForRowSet
in interface JdbcOperations
sql
- SQL query to executeargs
- arguments to bind to the queryargTypes
- SQL types of the arguments
(constants from java.sql.Types
)javax.sql.rowset.CachedRowSet
)DataAccessException
- if there is any problem executing the queryJdbcOperations.queryForRowSet(String)
,
SqlRowSetResultSetExtractor
,
CachedRowSet
,
Types
public SqlRowSet queryForRowSet(java.lang.String sql, java.lang.Object... args) throws DataAccessException
JdbcOperations
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).
queryForRowSet
in interface JdbcOperations
sql
- SQL query to executeargs
- 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 scalejavax.sql.rowset.CachedRowSet
)DataAccessException
- if there is any problem executing the queryJdbcOperations.queryForRowSet(String)
,
SqlRowSetResultSetExtractor
,
CachedRowSet
protected int update(PreparedStatementCreator psc, PreparedStatementSetter pss) throws DataAccessException
DataAccessException
public int update(PreparedStatementCreator psc) throws DataAccessException
JdbcOperations
A PreparedStatementCreator can either be implemented directly or configured through a PreparedStatementCreatorFactory.
update
in interface JdbcOperations
psc
- object that provides SQL and any necessary parametersDataAccessException
- if there is any problem issuing the updatePreparedStatementCreatorFactory
public int update(PreparedStatementCreator psc, KeyHolder generatedKeyHolder) throws DataAccessException
JdbcOperations
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.
update
in interface JdbcOperations
psc
- object that provides SQL and any necessary parametersgeneratedKeyHolder
- KeyHolder that will hold the generated keysDataAccessException
- if there is any problem issuing the updatePreparedStatementCreatorFactory
,
GeneratedKeyHolder
public int update(java.lang.String sql, PreparedStatementSetter pss) throws DataAccessException
JdbcOperations
update
in interface JdbcOperations
sql
- SQL containing bind parameterspss
- helper that sets bind parameters. If this is null
we run an update with static SQL.DataAccessException
- if there is any problem issuing the updatepublic int update(java.lang.String sql, java.lang.Object[] args, int[] argTypes) throws DataAccessException
JdbcOperations
update
in interface JdbcOperations
sql
- SQL containing bind parametersargs
- arguments to bind to the queryargTypes
- SQL types of the arguments
(constants from java.sql.Types
)DataAccessException
- if there is any problem issuing the updateTypes
public int update(java.lang.String sql, java.lang.Object... args) throws DataAccessException
JdbcOperations
update
in interface JdbcOperations
sql
- SQL containing bind parametersargs
- 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 scaleDataAccessException
- if there is any problem issuing the updatepublic int[] batchUpdate(java.lang.String sql, BatchPreparedStatementSetter pss) throws DataAccessException
JdbcOperations
Will fall back to separate updates on a single PreparedStatement if the JDBC driver does not support batch updates.
batchUpdate
in interface JdbcOperations
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 methodDataAccessException
- if there is any problem issuing the updatepublic int[] batchUpdate(java.lang.String sql, java.util.List<java.lang.Object[]> batchArgs)
JdbcOperations
batchUpdate
in interface JdbcOperations
sql
- the SQL statement to executebatchArgs
- the List of Object arrays containing the batch of arguments for the querypublic int[] batchUpdate(java.lang.String sql, java.util.List<java.lang.Object[]> batchArgs, int[] argTypes)
JdbcOperations
batchUpdate
in interface JdbcOperations
sql
- the SQL statement to execute.batchArgs
- the List of Object arrays containing the batch of arguments for the queryargTypes
- SQL types of the arguments
(constants from java.sql.Types
)public <T> int[][] batchUpdate(java.lang.String sql, java.util.Collection<T> batchArgs, int batchSize, ParameterizedPreparedStatementSetter<T> pss)
JdbcOperations
batchUpdate
in interface JdbcOperations
sql
- the SQL statement to execute.batchArgs
- the List of Object arrays containing the batch of arguments for the querybatchSize
- batch sizepss
- ParameterizedPreparedStatementSetter to usepublic <T> T execute(CallableStatementCreator csc, CallableStatementCallback<T> action) throws DataAccessException
JdbcOperations
The callback action can return a result object, for example a domain object or a collection of domain objects.
execute
in interface JdbcOperations
csc
- object that can create a CallableStatement given a Connectionaction
- callback object that specifies the actionnull
DataAccessException
- if there is any problempublic <T> T execute(java.lang.String callString, CallableStatementCallback<T> action) throws DataAccessException
JdbcOperations
The callback action can return a result object, for example a domain object or a collection of domain objects.
execute
in interface JdbcOperations
callString
- the SQL call string to executeaction
- callback object that specifies the actionnull
DataAccessException
- if there is any problempublic java.util.Map<java.lang.String,java.lang.Object> call(CallableStatementCreator csc, java.util.List<SqlParameter> declaredParameters) throws DataAccessException
JdbcOperations
call
in interface JdbcOperations
csc
- object that provides SQL and any necessary parametersdeclaredParameters
- list of declared SqlParameter objectsDataAccessException
- if there is any problem issuing the updateprotected java.util.Map<java.lang.String,java.lang.Object> extractReturnedResults(java.sql.CallableStatement cs, java.util.List updateCountParameters, java.util.List resultSetParameters, int updateCount) throws java.sql.SQLException
cs
- JDBC wrapper for the stored procedureupdateCountParameters
- Parameter list of declared update count parameters for the stored procedureresultSetParameters
- Parameter list of declared resturn resultSet parameters for the stored procedurejava.sql.SQLException
protected java.util.Map<java.lang.String,java.lang.Object> extractOutputParameters(java.sql.CallableStatement cs, java.util.List<SqlParameter> parameters) throws java.sql.SQLException
cs
- JDBC wrapper for the stored procedureparameters
- parameter list for the stored procedurejava.sql.SQLException
protected java.util.Map<java.lang.String,java.lang.Object> processResultSet(java.sql.ResultSet rs, ResultSetSupportingSqlParameter param) throws java.sql.SQLException
rs
- the ResultSet to processparam
- the corresponding stored procedure parameterjava.sql.SQLException
protected RowMapper<java.util.Map<java.lang.String,java.lang.Object>> getColumnMapRowMapper()
ColumnMapRowMapper
protected <T> RowMapper<T> getSingleColumnRowMapper(java.lang.Class<T> requiredType)
requiredType
- the type that each result object is expected to matchSingleColumnRowMapper
protected java.util.Map<java.lang.String,java.lang.Object> createResultsMap()
If "isResultsMapCaseInsensitive" has been set to true, a linked case-insensitive Map will be created.
setResultsMapCaseInsensitive(boolean)
protected void applyStatementSettings(java.sql.Statement stmt) throws java.sql.SQLException
stmt
- the JDBC Statement to preparejava.sql.SQLException
- if thrown by JDBC APIsetFetchSize(int)
,
setMaxRows(int)
,
setQueryTimeout(int)
,
DataSourceUtils.applyTransactionTimeout(java.sql.Statement, javax.sql.DataSource)
protected PreparedStatementSetter newArgPreparedStatementSetter(java.lang.Object[] args)
args
- object array woth argumentsprotected PreparedStatementSetter newArgTypePreparedStatementSetter(java.lang.Object[] args, int[] argTypes)
args
- object array woth argumentsargTypes
- int array of SQLTypes for argumentsprotected void handleWarnings(java.sql.Statement stmt) throws java.sql.SQLException
stmt
- the current JDBC statementSQLWarningException
- if not ignoring warningsjava.sql.SQLException
SQLWarningException
protected void handleWarnings(java.sql.SQLWarning warning) throws SQLWarningException
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 raisedprivate static java.lang.String getSql(java.lang.Object sqlProvider)
sqlProvider
- object that's potentially a SqlProvidernull
SqlProvider