public interface JdbcOperations
JdbcTemplate
. Not often used directly, but a useful
option to enhance testability, as it can easily be mocked or stubbed.
Alternatively, the standard JDBC infrastructure can be mocked.
However, mocking this interface constitutes significantly less work.
As an alternative to a mock objects approach to testing data access code,
consider the powerful integration testing support provided in the
org.springframework.test
package, shipped in
spring-test.jar
.
JdbcTemplate
Modifier and Type | Method and Description |
---|---|
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.
|
<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.
|
<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)
Deprecated.
in favor of
queryForObject(String, Class) |
int |
queryForInt(java.lang.String sql,
java.lang.Object... args)
Deprecated.
in favor of
queryForObject(String, Class, Object[]) )} |
int |
queryForInt(java.lang.String sql,
java.lang.Object[] args,
int[] argTypes)
Deprecated.
in favor of
queryForObject(String, Object[], int[], Class) )} |
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)
Deprecated.
in favor of
queryForObject(String, Class) |
long |
queryForLong(java.lang.String sql,
java.lang.Object... args)
Deprecated.
in favor of
queryForObject(String, Class, Object[]) )} |
long |
queryForLong(java.lang.String sql,
java.lang.Object[] args,
int[] argTypes)
Deprecated.
in favor of
queryForObject(String, Object[], int[], Class) )} |
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.
|
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.
|
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.
|
<T> T execute(ConnectionCallback<T> action) throws DataAccessException
The callback action can return a result object, for example a domain object or a collection of domain objects.
action
- the callback object that specifies the actionnull
DataAccessException
- if there is any problem<T> T execute(StatementCallback<T> action) throws DataAccessException
The callback action can return a result object, for example a domain object or a collection of domain objects.
action
- callback object that specifies the actionnull
DataAccessException
- if there is any problemvoid execute(java.lang.String sql) throws DataAccessException
sql
- static SQL to executeDataAccessException
- if there is any problem<T> T query(java.lang.String sql, ResultSetExtractor<T> rse) throws DataAccessException
Uses a JDBC Statement, not a PreparedStatement. If you want to
execute a static query with a PreparedStatement, use the overloaded
query
method with null
as argument array.
sql
- SQL query to executerse
- object that will extract all rows of resultsDataAccessException
- if there is any problem executing the queryquery(String, Object[], ResultSetExtractor)
void query(java.lang.String sql, RowCallbackHandler rch) throws DataAccessException
Uses a JDBC Statement, not a PreparedStatement. If you want to
execute a static query with a PreparedStatement, use the overloaded
query
method with null
as argument array.
sql
- SQL query to executerch
- object that will extract results, one row at a timeDataAccessException
- if there is any problem executing the queryquery(String, Object[], RowCallbackHandler)
<T> java.util.List<T> query(java.lang.String sql, RowMapper<T> rowMapper) throws DataAccessException
Uses a JDBC Statement, not a PreparedStatement. If you want to
execute a static query with a PreparedStatement, use the overloaded
query
method with null
as argument array.
sql
- SQL query to executerowMapper
- object that will map one object per rowDataAccessException
- if there is any problem executing the queryquery(String, Object[], RowMapper)
<T> T queryForObject(java.lang.String sql, RowMapper<T> rowMapper) throws DataAccessException
Uses a JDBC Statement, not a PreparedStatement. If you want to
execute a static query with a PreparedStatement, use the overloaded
queryForObject(String, RowMapper, Object...)
method with
null
as argument array.
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 queryqueryForObject(String, Object[], RowMapper)
<T> T queryForObject(java.lang.String sql, java.lang.Class<T> requiredType) throws DataAccessException
Uses a JDBC Statement, not a PreparedStatement. If you want to
execute a static query with a PreparedStatement, use the overloaded
queryForObject(String, Class, Object...)
method with
null
as argument array.
This method is useful for running static SQL with a known outcome. The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.
sql
- SQL query to 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 queryqueryForObject(String, Object[], Class)
java.util.Map<java.lang.String,java.lang.Object> queryForMap(java.lang.String sql) throws DataAccessException
Uses a JDBC Statement, not a PreparedStatement. If you want to
execute a static query with a PreparedStatement, use the overloaded
queryForMap(String, Object...)
method with null
as argument array.
The query is expected to be a single row query; the result row will be mapped to a Map (one entry for each column, using the column name as the key).
sql
- SQL query to executeIncorrectResultSizeDataAccessException
- if the query does not
return exactly one rowDataAccessException
- if there is any problem executing the queryqueryForMap(String, Object[])
,
ColumnMapRowMapper
@Deprecated long queryForLong(java.lang.String sql) throws DataAccessException
queryForObject(String, Class)
Uses a JDBC Statement, not a PreparedStatement. If you want to
execute a static query with a PreparedStatement, use the overloaded
queryForLong
method with null
as argument array.
This method is useful for running static SQL with a known outcome. The query is expected to be a single row/single column query that results in a long value.
sql
- SQL query to 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 queryqueryForLong(String, Object[])
@Deprecated int queryForInt(java.lang.String sql) throws DataAccessException
queryForObject(String, Class)
Uses a JDBC Statement, not a PreparedStatement. If you want to
execute a static query with a PreparedStatement, use the overloaded
queryForInt
method with null
as argument array.
This method is useful for running static SQL with a known outcome. The query is expected to be a single row/single column query that results in an int value.
sql
- SQL query to 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 queryqueryForInt(String, Object[])
<T> java.util.List<T> queryForList(java.lang.String sql, java.lang.Class<T> elementType) throws DataAccessException
Uses a JDBC Statement, not a PreparedStatement. If you want to
execute a static query with a PreparedStatement, use the overloaded
queryForList
method with null
as argument array.
The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.
sql
- SQL query to executeelementType
- the required type of element in the result list
(for example, Integer.class
)DataAccessException
- if there is any problem executing the queryqueryForList(String, Object[], Class)
,
SingleColumnRowMapper
java.util.List<java.util.Map<java.lang.String,java.lang.Object>> queryForList(java.lang.String sql) throws DataAccessException
Uses a JDBC Statement, not a PreparedStatement. If you want to
execute a static query with a PreparedStatement, use the overloaded
queryForList
method with null
as argument array.
The results will be mapped to a List (one entry for each row) of Maps (one entry for each column using the column name as the key). Each element in the list will be of the form returned by this interface's queryForMap() methods.
sql
- SQL query to executeDataAccessException
- if there is any problem executing the queryqueryForList(String, Object[])
SqlRowSet queryForRowSet(java.lang.String sql) throws DataAccessException
Uses a JDBC Statement, not a PreparedStatement. If you want to
execute a static query with a PreparedStatement, use the overloaded
queryForRowSet
method with null
as argument array.
The results will be mapped to an SqlRowSet which holds the data in a disconnected fashion. This wrapper will translate any SQLExceptions thrown.
Note that that, for the default implementation, JDBC RowSet support needs to
be available at runtime: by default, Sun's com.sun.rowset.CachedRowSetImpl
class is used, which is part of JDK 1.5+ and also available separately as part of
Sun's JDBC RowSet Implementations download (rowset.jar).
sql
- SQL query to executejavax.sql.rowset.CachedRowSet
)DataAccessException
- if there is any problem executing the queryqueryForRowSet(String, Object[])
,
SqlRowSetResultSetExtractor
,
CachedRowSet
int update(java.lang.String sql) throws DataAccessException
sql
- static SQL to executeDataAccessException
- if there is any problem.int[] batchUpdate(java.lang.String[] sql) throws DataAccessException
Will fall back to separate updates on a single Statement if the JDBC driver does not support batch updates.
sql
- defining an array of SQL statements that will be executed.DataAccessException
- if there is any problem executing the batch<T> T execute(PreparedStatementCreator psc, PreparedStatementCallback<T> action) throws DataAccessException
The callback action can return a result object, for example a domain object or a collection of domain objects.
psc
- object that can create a PreparedStatement given a Connectionaction
- callback object that specifies the actionnull
DataAccessException
- if there is any problem<T> T execute(java.lang.String sql, PreparedStatementCallback<T> action) throws DataAccessException
The callback action can return a result object, for example a domain object or a collection of domain objects.
sql
- SQL to executeaction
- callback object that specifies the actionnull
DataAccessException
- if there is any problem<T> T query(PreparedStatementCreator psc, ResultSetExtractor<T> rse) throws DataAccessException
A PreparedStatementCreator can either be implemented directly or configured through a PreparedStatementCreatorFactory.
psc
- object that can create a PreparedStatement given a Connectionrse
- object that will extract resultsDataAccessException
- if there is any problemPreparedStatementCreatorFactory
<T> T query(java.lang.String sql, PreparedStatementSetter pss, ResultSetExtractor<T> rse) throws DataAccessException
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 problem<T> T query(java.lang.String sql, java.lang.Object[] args, int[] argTypes, ResultSetExtractor<T> rse) throws DataAccessException
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
<T> T query(java.lang.String sql, java.lang.Object[] args, ResultSetExtractor<T> rse) throws DataAccessException
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 fails<T> T query(java.lang.String sql, ResultSetExtractor<T> rse, java.lang.Object... args) throws DataAccessException
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 failsvoid query(PreparedStatementCreator psc, RowCallbackHandler rch) throws DataAccessException
A PreparedStatementCreator can either be implemented directly or configured through a PreparedStatementCreatorFactory.
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
void query(java.lang.String sql, PreparedStatementSetter pss, RowCallbackHandler rch) throws DataAccessException
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 failsvoid query(java.lang.String sql, java.lang.Object[] args, int[] argTypes, RowCallbackHandler rch) throws DataAccessException
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
void query(java.lang.String sql, java.lang.Object[] args, RowCallbackHandler rch) throws DataAccessException
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 failsvoid query(java.lang.String sql, RowCallbackHandler rch, java.lang.Object... args) throws DataAccessException
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 fails<T> java.util.List<T> query(PreparedStatementCreator psc, RowMapper<T> rowMapper) throws DataAccessException
A PreparedStatementCreator can either be implemented directly or configured through a PreparedStatementCreatorFactory.
psc
- object that can create a PreparedStatement given a ConnectionrowMapper
- object that will map one object per rowDataAccessException
- if there is any problemPreparedStatementCreatorFactory
<T> java.util.List<T> query(java.lang.String sql, PreparedStatementSetter pss, RowMapper<T> rowMapper) throws DataAccessException
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 fails<T> java.util.List<T> query(java.lang.String sql, java.lang.Object[] args, int[] argTypes, RowMapper<T> rowMapper) throws DataAccessException
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
<T> java.util.List<T> query(java.lang.String sql, java.lang.Object[] args, RowMapper<T> rowMapper) throws DataAccessException
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 fails<T> java.util.List<T> query(java.lang.String sql, RowMapper<T> rowMapper, java.lang.Object... args) throws DataAccessException
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 fails<T> T queryForObject(java.lang.String sql, java.lang.Object[] args, int[] argTypes, RowMapper<T> rowMapper) throws DataAccessException
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 fails<T> T queryForObject(java.lang.String sql, java.lang.Object[] args, RowMapper<T> rowMapper) throws DataAccessException
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 fails<T> T queryForObject(java.lang.String sql, RowMapper<T> rowMapper, java.lang.Object... args) throws DataAccessException
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 fails<T> T queryForObject(java.lang.String sql, java.lang.Object[] args, int[] argTypes, java.lang.Class<T> requiredType) throws DataAccessException
The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.
sql
- SQL query to 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 failsqueryForObject(String, Class)
,
Types
<T> T queryForObject(java.lang.String sql, java.lang.Object[] args, java.lang.Class<T> requiredType) throws DataAccessException
The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.
sql
- SQL query to 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 failsqueryForObject(String, Class)
<T> T queryForObject(java.lang.String sql, java.lang.Class<T> requiredType, java.lang.Object... args) throws DataAccessException
The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.
sql
- SQL query to 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 failsqueryForObject(String, Class)
java.util.Map<java.lang.String,java.lang.Object> queryForMap(java.lang.String sql, java.lang.Object[] args, int[] argTypes) throws DataAccessException
The query is expected to be a single row query; the result row will be mapped to a Map (one entry for each column, using the column name as the key).
sql
- SQL query to 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 failsqueryForMap(String)
,
ColumnMapRowMapper
,
Types
java.util.Map<java.lang.String,java.lang.Object> queryForMap(java.lang.String sql, java.lang.Object... args) throws DataAccessException
The query is expected to be a single row query; the result row will be mapped to a Map (one entry for each column, using the column name as the key).
sql
- SQL query to 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 failsqueryForMap(String)
,
ColumnMapRowMapper
@Deprecated long queryForLong(java.lang.String sql, java.lang.Object[] args, int[] argTypes) throws DataAccessException
queryForObject(String, Object[], int[], Class)
)}The query is expected to be a single row/single column query that results in a long value.
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 failsqueryForLong(String)
,
Types
@Deprecated long queryForLong(java.lang.String sql, java.lang.Object... args) throws DataAccessException
queryForObject(String, Class, Object[])
)}The query is expected to be a single row/single column query that results in a long value.
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 failsqueryForLong(String)
@Deprecated int queryForInt(java.lang.String sql, java.lang.Object[] args, int[] argTypes) throws DataAccessException
queryForObject(String, Object[], int[], Class)
)}The query is expected to be a single row/single column query that results in an int value.
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 failsqueryForInt(String)
,
Types
@Deprecated int queryForInt(java.lang.String sql, java.lang.Object... args) throws DataAccessException
queryForObject(String, Class, Object[])
)}The query is expected to be a single row/single column query that results in an int value.
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 failsqueryForInt(String)
<T> java.util.List<T> queryForList(java.lang.String sql, java.lang.Object[] args, int[] argTypes, java.lang.Class<T> elementType) throws DataAccessException
The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.
sql
- SQL query to 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 failsqueryForList(String, Class)
,
SingleColumnRowMapper
<T> java.util.List<T> queryForList(java.lang.String sql, java.lang.Object[] args, java.lang.Class<T> elementType) throws DataAccessException
The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.
sql
- SQL query to 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 failsqueryForList(String, Class)
,
SingleColumnRowMapper
<T> java.util.List<T> queryForList(java.lang.String sql, java.lang.Class<T> elementType, java.lang.Object... args) throws DataAccessException
The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.
sql
- SQL query to 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 failsqueryForList(String, Class)
,
SingleColumnRowMapper
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
The results will be mapped to a List (one entry for each row) of Maps (one entry for each column, using the column name as the key). Thus Each element in the list will be of the form returned by this interface's queryForMap() methods.
sql
- SQL query to executeargs
- arguments to bind to the queryargTypes
- SQL types of the arguments
(constants from java.sql.Types
)DataAccessException
- if the query failsqueryForList(String)
,
Types
java.util.List<java.util.Map<java.lang.String,java.lang.Object>> queryForList(java.lang.String sql, java.lang.Object... args) throws DataAccessException
The results will be mapped to a List (one entry for each row) of Maps (one entry for each column, using the column name as the key). Each element in the list will be of the form returned by this interface's queryForMap() methods.
sql
- SQL query to 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 failsqueryForList(String)
SqlRowSet queryForRowSet(java.lang.String sql, java.lang.Object[] args, int[] argTypes) throws DataAccessException
The results will be mapped to an SqlRowSet which holds the data in a disconnected fashion. This wrapper will translate any SQLExceptions thrown.
Note that that, for the default implementation, JDBC RowSet support needs to
be available at runtime: by default, Sun's com.sun.rowset.CachedRowSetImpl
class is used, which is part of JDK 1.5+ and also available separately as part of
Sun's JDBC RowSet Implementations download (rowset.jar).
sql
- SQL query to 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 queryqueryForRowSet(String)
,
SqlRowSetResultSetExtractor
,
CachedRowSet
,
Types
SqlRowSet queryForRowSet(java.lang.String sql, java.lang.Object... args) throws DataAccessException
The results will be mapped to an SqlRowSet which holds the data in a disconnected fashion. This wrapper will translate any SQLExceptions thrown.
Note that that, for the default implementation, JDBC RowSet support needs to
be available at runtime: by default, Sun's com.sun.rowset.CachedRowSetImpl
class is used, which is part of JDK 1.5+ and also available separately as part of
Sun's JDBC RowSet Implementations download (rowset.jar).
sql
- SQL query to 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 queryqueryForRowSet(String)
,
SqlRowSetResultSetExtractor
,
CachedRowSet
int update(PreparedStatementCreator psc) throws DataAccessException
A PreparedStatementCreator can either be implemented directly or configured through a PreparedStatementCreatorFactory.
psc
- object that provides SQL and any necessary parametersDataAccessException
- if there is any problem issuing the updatePreparedStatementCreatorFactory
int update(PreparedStatementCreator psc, KeyHolder generatedKeyHolder) throws DataAccessException
Note that the given PreparedStatementCreator has to create a statement with activated extraction of generated keys (a JDBC 3.0 feature). This can either be done directly or through using a PreparedStatementCreatorFactory.
psc
- object that provides SQL and any necessary parametersgeneratedKeyHolder
- KeyHolder that will hold the generated keysDataAccessException
- if there is any problem issuing the updatePreparedStatementCreatorFactory
,
GeneratedKeyHolder
int update(java.lang.String sql, PreparedStatementSetter pss) throws DataAccessException
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 updateint update(java.lang.String sql, java.lang.Object[] args, int[] argTypes) throws DataAccessException
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
int update(java.lang.String sql, java.lang.Object... args) throws DataAccessException
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 updateint[] batchUpdate(java.lang.String sql, BatchPreparedStatementSetter pss) throws DataAccessException
Will fall back to separate updates on a single PreparedStatement if the JDBC driver does not support batch updates.
sql
- defining PreparedStatement that will be reused.
All statements in the batch will use the same SQL.pss
- object to set parameters on the PreparedStatement
created by this methodDataAccessException
- if there is any problem issuing the updateint[] batchUpdate(java.lang.String sql, java.util.List<java.lang.Object[]> batchArgs)
sql
- the SQL statement to executebatchArgs
- the List of Object arrays containing the batch of arguments for the queryint[] batchUpdate(java.lang.String sql, java.util.List<java.lang.Object[]> batchArgs, int[] argTypes)
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
)<T> int[][] batchUpdate(java.lang.String sql, java.util.Collection<T> batchArgs, int batchSize, ParameterizedPreparedStatementSetter<T> pss)
sql
- the SQL statement to execute.batchArgs
- the List of Object arrays containing the batch of arguments for the querybatchSize
- batch sizepss
- ParameterizedPreparedStatementSetter to use<T> T execute(CallableStatementCreator csc, CallableStatementCallback<T> action) throws DataAccessException
The callback action can return a result object, for example a domain object or a collection of domain objects.
csc
- object that can create a CallableStatement given a Connectionaction
- callback object that specifies the actionnull
DataAccessException
- if there is any problem<T> T execute(java.lang.String callString, CallableStatementCallback<T> action) throws DataAccessException
The callback action can return a result object, for example a domain object or a collection of domain objects.
callString
- the SQL call string to executeaction
- callback object that specifies the actionnull
DataAccessException
- if there is any problemjava.util.Map<java.lang.String,java.lang.Object> call(CallableStatementCreator csc, java.util.List<SqlParameter> declaredParameters) throws DataAccessException
csc
- object that provides SQL and any necessary parametersdeclaredParameters
- list of declared SqlParameter objectsDataAccessException
- if there is any problem issuing the update