|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface JdbcOperations
Interface specifying a basic set of JDBC operations.
Implemented by 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-mock.jar
.
JdbcTemplate
Method Summary | |
---|---|
int[] |
batchUpdate(String[] sql)
Issue multiple SQL updates on a single Statement, using JDBC 2.0 batching. |
int[] |
batchUpdate(String sql,
BatchPreparedStatementSetter pss)
Issue multiple updates on a single PreparedStatement, using JDBC 2.0 batch updates and a BatchPreparedStatementSetter to set values. |
Map |
call(CallableStatementCreator csc,
List declaredParameters)
Execute a SQL call using a CallableStatementCreator to provide SQL and any required parameters. |
Object |
execute(CallableStatementCreator csc,
CallableStatementCallback action)
Execute a JDBC data access operation, implemented as callback action working on a JDBC CallableStatement. |
Object |
execute(ConnectionCallback action)
Execute a JDBC data access operation, implemented as callback action working on a JDBC Connection. |
Object |
execute(PreparedStatementCreator psc,
PreparedStatementCallback action)
Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement. |
Object |
execute(StatementCallback action)
Execute a JDBC data access operation, implemented as callback action working on a JDBC Statement. |
void |
execute(String sql)
Issue a single SQL execute, typically a DDL statement. |
Object |
execute(String callString,
CallableStatementCallback action)
Execute a JDBC data access operation, implemented as callback action working on a JDBC CallableStatement. |
Object |
execute(String sql,
PreparedStatementCallback action)
Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement. |
Object |
query(PreparedStatementCreator psc,
ResultSetExtractor 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. |
List |
query(PreparedStatementCreator psc,
RowMapper rowMapper)
Query using a prepared statement, mapping each row to a Java object via a RowMapper. |
Object |
query(String sql,
Object[] args,
int[] argTypes,
ResultSetExtractor 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(String sql,
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. |
List |
query(String sql,
Object[] args,
int[] argTypes,
RowMapper 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. |
Object |
query(String sql,
Object[] args,
ResultSetExtractor 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(String sql,
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. |
List |
query(String sql,
Object[] args,
RowMapper 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. |
Object |
query(String sql,
PreparedStatementSetter pss,
ResultSetExtractor rse)
Query using a prepared statement, reading the ResultSet with a ResultSetExtractor. |
void |
query(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. |
List |
query(String sql,
PreparedStatementSetter pss,
RowMapper 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. |
Object |
query(String sql,
ResultSetExtractor rse)
Execute a query given static SQL, reading the ResultSet with a ResultSetExtractor. |
void |
query(String sql,
RowCallbackHandler rch)
Execute a query given static SQL, reading the ResultSet on a per-row basis with a RowCallbackHandler. |
List |
query(String sql,
RowMapper rowMapper)
Execute a query given static SQL, mapping each row to a Java object via a RowMapper. |
int |
queryForInt(String sql)
Execute a query that results in an int value, given static SQL. |
int |
queryForInt(String sql,
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(String sql,
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. |
List |
queryForList(String sql)
Execute a query for a result list, given static SQL. |
List |
queryForList(String sql,
Class elementType)
Execute a query for a result list, given static SQL. |
List |
queryForList(String sql,
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. |
List |
queryForList(String sql,
Object[] args,
Class 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. |
List |
queryForList(String sql,
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. |
List |
queryForList(String sql,
Object[] args,
int[] argTypes,
Class 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(String sql)
Execute a query that results in a long value, given static SQL. |
long |
queryForLong(String sql,
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(String sql,
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. |
Map |
queryForMap(String sql)
Execute a query for a result Map, given static SQL. |
Map |
queryForMap(String sql,
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. |
Map |
queryForMap(String sql,
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. |
Object |
queryForObject(String sql,
Class requiredType)
Execute a query for a result object, given static SQL. |
Object |
queryForObject(String sql,
Object[] args,
Class 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. |
Object |
queryForObject(String sql,
Object[] args,
int[] argTypes,
Class 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. |
Object |
queryForObject(String sql,
Object[] args,
int[] argTypes,
RowMapper 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. |
Object |
queryForObject(String sql,
Object[] args,
RowMapper 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. |
Object |
queryForObject(String sql,
RowMapper rowMapper)
Execute a query given static SQL, mapping a single result row to a Java object via a RowMapper. |
SqlRowSet |
queryForRowSet(String sql)
Execute a query for a SqlRowSet, given static SQL. |
SqlRowSet |
queryForRowSet(String sql,
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(String sql,
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 an update using a PreparedStatementCreator to provide SQL and any required parameters. |
int |
update(PreparedStatementCreator psc,
KeyHolder generatedKeyHolder)
Issue an update using a PreparedStatementCreator to provide SQL and any required parameters. |
int |
update(String sql)
Issue a single SQL update. |
int |
update(String sql,
Object[] args)
Issue an update via a prepared statement, binding the given arguments. |
int |
update(String sql,
Object[] args,
int[] argTypes)
Issue an update via a prepared statement, binding the given arguments. |
int |
update(String sql,
PreparedStatementSetter pss)
Issue an update using a PreparedStatementSetter to set bind parameters, with given SQL. |
Method Detail |
---|
Object execute(ConnectionCallback 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 action
null
DataAccessException
- if there is any problemObject execute(StatementCallback 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 action
null
DataAccessException
- if there is any problemvoid execute(String sql) throws DataAccessException
sql
- static SQL to execute
DataAccessException
- if there is any problemObject query(String sql, ResultSetExtractor 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 results
DataAccessException
- if there is any problem executing the queryquery(String, Object[], ResultSetExtractor)
void query(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 time
DataAccessException
- if there is any problem executing the queryquery(String, Object[], RowCallbackHandler)
List query(String sql, RowMapper 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 row
DataAccessException
- if there is any problem executing the queryquery(String, Object[], RowMapper)
Object queryForObject(String sql, RowMapper 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
method with null
as argument array.
sql
- SQL query to executerowMapper
- object that will map one object per row
IncorrectResultSizeDataAccessException
- if the query does not
return exactly one row
DataAccessException
- if there is any problem executing the queryqueryForObject(String, Object[], RowMapper)
Object queryForObject(String sql, Class 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
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 match
null
in case of SQL NULL
IncorrectResultSizeDataAccessException
- if the query does not return
exactly one row, or does not return exactly one column in that row
DataAccessException
- if there is any problem executing the queryqueryForObject(String, Object[], Class)
Map queryForMap(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
method with null
as argument array.
The query is expected to be a single row query; the result row will be mapped to a Map (one entry for each column, using the column name as the key).
sql
- SQL query to execute
IncorrectResultSizeDataAccessException
- if the query does not
return exactly one row
DataAccessException
- if there is any problem executing the queryqueryForMap(String, Object[])
,
ColumnMapRowMapper
long queryForLong(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
queryForLong
method with null
as argument array.
This method is useful for running static SQL with a known outcome. The query is expected to be a single row/single column query that results in a long value.
sql
- SQL query to execute
IncorrectResultSizeDataAccessException
- if the query does not return
exactly one row, or does not return exactly one column in that row
DataAccessException
- if there is any problem executing the queryqueryForLong(String, Object[])
int queryForInt(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
queryForInt
method with null
as argument array.
This method is useful for running static SQL with a known outcome. The query is expected to be a single row/single column query that results in an int value.
sql
- SQL query to execute
IncorrectResultSizeDataAccessException
- if the query does not return
exactly one row, or does not return exactly one column in that row
DataAccessException
- if there is any problem executing the queryqueryForInt(String, Object[])
List queryForList(String sql, Class 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
List queryForList(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 execute
DataAccessException
- if there is any problem executing the queryqueryForList(String, Object[])
SqlRowSet queryForRowSet(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 execute
javax.sql.rowset.CachedRowSet
)
DataAccessException
- if there is any problem executing the queryqueryForRowSet(String, Object[])
,
SqlRowSetResultSetExtractor
,
CachedRowSet
int update(String sql) throws DataAccessException
sql
- static SQL to execute
DataAccessException
- if there is any problem.int[] batchUpdate(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 batchObject execute(PreparedStatementCreator psc, PreparedStatementCallback 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 action
null
DataAccessException
- if there is any problemObject execute(String sql, PreparedStatementCallback 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 action
null
DataAccessException
- if there is any problemObject query(PreparedStatementCreator psc, ResultSetExtractor 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 results
DataAccessException
- if there is any problemPreparedStatementCreatorFactory
Object query(String sql, PreparedStatementSetter pss, ResultSetExtractor 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 results
DataAccessException
- if there is any problemObject query(String sql, Object[] args, int[] argTypes, ResultSetExtractor 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 results
DataAccessException
- if the query failsTypes
Object query(String sql, Object[] args, ResultSetExtractor 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 results
DataAccessException
- 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 time
DataAccessException
- if there is any problemPreparedStatementCreatorFactory
void query(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 time
DataAccessException
- if the query failsvoid query(String sql, 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 time
DataAccessException
- if the query failsTypes
void query(String sql, 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 time
DataAccessException
- if the query failsList query(PreparedStatementCreator psc, RowMapper 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 row
DataAccessException
- if there is any problemPreparedStatementCreatorFactory
List query(String sql, PreparedStatementSetter pss, RowMapper 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 row
DataAccessException
- if the query failsList query(String sql, Object[] args, int[] argTypes, RowMapper 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 row
DataAccessException
- if the query failsTypes
List query(String sql, Object[] args, RowMapper 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 row
DataAccessException
- if the query failsObject queryForObject(String sql, Object[] args, int[] argTypes, RowMapper 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 row
IncorrectResultSizeDataAccessException
- if the query does not
return exactly one row
DataAccessException
- if the query failsObject queryForObject(String sql, Object[] args, RowMapper 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 row
IncorrectResultSizeDataAccessException
- if the query does not
return exactly one row
DataAccessException
- if the query failsObject queryForObject(String sql, Object[] args, int[] argTypes, Class 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 match
null
in case of SQL NULL
IncorrectResultSizeDataAccessException
- if the query does not return
exactly one row, or does not return exactly one column in that row
DataAccessException
- if the query failsqueryForObject(String, Class)
,
Types
Object queryForObject(String sql, Object[] args, Class 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 match
null
in case of SQL NULL
IncorrectResultSizeDataAccessException
- if the query does not return
exactly one row, or does not return exactly one column in that row
DataAccessException
- if the query failsqueryForObject(String, Class)
Map queryForMap(String sql, 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 row
DataAccessException
- if the query failsqueryForMap(String)
,
ColumnMapRowMapper
,
Types
Map queryForMap(String sql, 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 scale
IncorrectResultSizeDataAccessException
- if the query does not
return exactly one row
DataAccessException
- if the query failsqueryForMap(String)
,
ColumnMapRowMapper
long queryForLong(String sql, Object[] args, int[] argTypes) throws DataAccessException
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 row
DataAccessException
- if the query failsqueryForLong(String)
,
Types
long queryForLong(String sql, Object[] args) throws DataAccessException
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 scale
IncorrectResultSizeDataAccessException
- if the query does not return
exactly one row, or does not return exactly one column in that row
DataAccessException
- if the query failsqueryForLong(String)
int queryForInt(String sql, Object[] args, int[] argTypes) throws DataAccessException
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 row
DataAccessException
- if the query failsqueryForInt(String)
,
Types
int queryForInt(String sql, Object[] args) throws DataAccessException
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 scale
IncorrectResultSizeDataAccessException
- if the query does not return
exactly one row, or does not return exactly one column in that row
DataAccessException
- if the query failsqueryForInt(String)
List queryForList(String sql, Object[] args, int[] argTypes, Class 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
List queryForList(String sql, Object[] args, Class 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
List queryForList(String sql, 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
List queryForList(String sql, 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 scale
DataAccessException
- if the query failsqueryForList(String)
SqlRowSet queryForRowSet(String sql, 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(String sql, 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 scale
javax.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 parameters
DataAccessException
- 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 keys
DataAccessException
- if there is any problem issuing the updatePreparedStatementCreatorFactory
,
GeneratedKeyHolder
int update(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(String sql, 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(String sql, 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 scale
DataAccessException
- if there is any problem issuing the updateint[] batchUpdate(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 method
DataAccessException
- if there is any problem issuing the updateObject execute(CallableStatementCreator csc, CallableStatementCallback 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 action
null
DataAccessException
- if there is any problemObject execute(String callString, CallableStatementCallback 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 action
null
DataAccessException
- if there is any problemMap call(CallableStatementCreator csc, List declaredParameters) throws DataAccessException
csc
- object that provides SQL and any necessary parametersdeclaredParameters
- list of declared SqlParameter objects
DataAccessException
- if there is any problem issuing the update
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |