Spring Framework

org.springframework.jdbc.core
Interface JdbcOperations

All Known Implementing Classes:
JdbcTemplate

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-test.jar.

Author:
Rod Johnson, Juergen Hoeller
See Also:
JdbcTemplate

Method Summary
 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)
          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.
 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.
 

Method Detail

execute

<T> T execute(ConnectionCallback<T> action)
          throws DataAccessException
Execute a JDBC data access operation, implemented as callback action working on a JDBC Connection. This allows for implementing arbitrary data access operations, within Spring's managed JDBC environment: that is, participating in Spring-managed transactions and converting JDBC SQLExceptions into Spring's DataAccessException hierarchy.

The callback action can return a result object, for example a domain object or a collection of domain objects.

Parameters:
action - the callback object that specifies the action
Returns:
a result object returned by the action, or null
Throws:
DataAccessException - if there is any problem

execute

<T> T execute(StatementCallback<T> action)
          throws DataAccessException
Execute a JDBC data access operation, implemented as callback action working on a JDBC Statement. This allows for implementing arbitrary data access operations on a single Statement, within Spring's managed JDBC environment: that is, participating in Spring-managed transactions and converting JDBC SQLExceptions into Spring's DataAccessException hierarchy.

The callback action can return a result object, for example a domain object or a collection of domain objects.

Parameters:
action - callback object that specifies the action
Returns:
a result object returned by the action, or null
Throws:
DataAccessException - if there is any problem

execute

void execute(java.lang.String sql)
             throws DataAccessException
Issue a single SQL execute, typically a DDL statement.

Parameters:
sql - static SQL to execute
Throws:
DataAccessException - if there is any problem

query

<T> T query(java.lang.String sql,
            ResultSetExtractor<T> rse)
        throws DataAccessException
Execute a query given static SQL, reading the ResultSet with a ResultSetExtractor.

Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded query method with null as argument array.

Parameters:
sql - SQL query to execute
rse - object that will extract all rows of results
Returns:
an arbitrary result object, as returned by the ResultSetExtractor
Throws:
DataAccessException - if there is any problem executing the query
See Also:
query(String, Object[], ResultSetExtractor)

query

void query(java.lang.String sql,
           RowCallbackHandler rch)
           throws DataAccessException
Execute a query given static SQL, reading the ResultSet on a per-row basis with a RowCallbackHandler.

Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded query method with null as argument array.

Parameters:
sql - SQL query to execute
rch - object that will extract results, one row at a time
Throws:
DataAccessException - if there is any problem executing the query
See Also:
query(String, Object[], RowCallbackHandler)

query

<T> java.util.List<T> query(java.lang.String sql,
                            RowMapper<T> rowMapper)
                        throws DataAccessException
Execute a query given static SQL, mapping each row to a Java object via a RowMapper.

Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded query method with null as argument array.

Parameters:
sql - SQL query to execute
rowMapper - object that will map one object per row
Returns:
the result List, containing mapped objects
Throws:
DataAccessException - if there is any problem executing the query
See Also:
query(String, Object[], RowMapper)

queryForObject

<T> T queryForObject(java.lang.String sql,
                     RowMapper<T> rowMapper)
                 throws DataAccessException
Execute a query given static SQL, mapping a single result row to a Java object via a RowMapper.

Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded queryForObject method with null as argument array.

Parameters:
sql - SQL query to execute
rowMapper - object that will map one object per row
Returns:
the single mapped object
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row
DataAccessException - if there is any problem executing the query
See Also:
queryForObject(String, Object[], RowMapper)

queryForObject

<T> T queryForObject(java.lang.String sql,
                     java.lang.Class<T> requiredType)
                 throws DataAccessException
Execute a query for a result object, given static SQL.

Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded queryForObject method with null as argument array.

This method is useful for running static SQL with a known outcome. The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.

Parameters:
sql - SQL query to execute
requiredType - the type that the result object is expected to match
Returns:
the result object of the required type, or null in case of SQL NULL
Throws:
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 query
See Also:
queryForObject(String, Object[], Class)

queryForMap

java.util.Map<java.lang.String,java.lang.Object> queryForMap(java.lang.String sql)
                                                             throws DataAccessException
Execute a query for a result Map, given static SQL.

Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded queryForMap method with null as argument array.

The query is expected to be a single row query; the result row will be mapped to a Map (one entry for each column, using the column name as the key).

Parameters:
sql - SQL query to execute
Returns:
the result Map (one entry for each column, using the column name as the key)
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row
DataAccessException - if there is any problem executing the query
See Also:
queryForMap(String, Object[]), ColumnMapRowMapper

queryForLong

long queryForLong(java.lang.String sql)
                  throws DataAccessException
Execute a query that results in a long value, given static SQL.

Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded queryForLong method with null as argument array.

This method is useful for running static SQL with a known outcome. The query is expected to be a single row/single column query that results in a long value.

Parameters:
sql - SQL query to execute
Returns:
the long value, or 0 in case of SQL NULL
Throws:
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 query
See Also:
queryForLong(String, Object[])

queryForInt

int queryForInt(java.lang.String sql)
                throws DataAccessException
Execute a query that results in an int value, given static SQL.

Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded queryForInt method with null as argument array.

This method is useful for running static SQL with a known outcome. The query is expected to be a single row/single column query that results in an int value.

Parameters:
sql - SQL query to execute
Returns:
the int value, or 0 in case of SQL NULL
Throws:
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 query
See Also:
queryForInt(String, Object[])

queryForList

<T> java.util.List<T> queryForList(java.lang.String sql,
                                   java.lang.Class<T> elementType)
                               throws DataAccessException
Execute a query for a result list, given static SQL.

Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded queryForList method with null as argument array.

The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.

Parameters:
sql - SQL query to execute
elementType - the required type of element in the result list (for example, Integer.class)
Returns:
a List of objects that match the specified element type
Throws:
DataAccessException - if there is any problem executing the query
See Also:
queryForList(String, Object[], Class), SingleColumnRowMapper

queryForList

java.util.List<java.util.Map<java.lang.String,java.lang.Object>> queryForList(java.lang.String sql)
                                                                              throws DataAccessException
Execute a query for a result list, given static SQL.

Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded queryForList method with null as argument array.

The results will be mapped to a List (one entry for each row) of Maps (one entry for each column using the column name as the key). Each element in the list will be of the form returned by this interface's queryForMap() methods.

Parameters:
sql - SQL query to execute
Returns:
an List that contains a Map per row
Throws:
DataAccessException - if there is any problem executing the query
See Also:
queryForList(String, Object[])

queryForRowSet

SqlRowSet queryForRowSet(java.lang.String sql)
                         throws DataAccessException
Execute a query for a SqlRowSet, given static SQL.

Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded queryForRowSet method with null as argument array.

The results will be mapped to an SqlRowSet which holds the data in a disconnected fashion. This wrapper will translate any SQLExceptions thrown.

Note that that, for the default implementation, JDBC RowSet support needs to be available at runtime: by default, Sun's com.sun.rowset.CachedRowSetImpl class is used, which is part of JDK 1.5+ and also available separately as part of Sun's JDBC RowSet Implementations download (rowset.jar).

Parameters:
sql - SQL query to execute
Returns:
a SqlRowSet representation (possibly a wrapper around a javax.sql.rowset.CachedRowSet)
Throws:
DataAccessException - if there is any problem executing the query
See Also:
queryForRowSet(String, Object[]), SqlRowSetResultSetExtractor, CachedRowSet

update

int update(java.lang.String sql)
           throws DataAccessException
Issue a single SQL update operation (such as an insert, update or delete statement).

Parameters:
sql - static SQL to execute
Returns:
the number of rows affected
Throws:
DataAccessException - if there is any problem.

batchUpdate

int[] batchUpdate(java.lang.String[] sql)
                  throws DataAccessException
Issue multiple SQL updates on a single JDBC Statement using batching.

Will fall back to separate updates on a single Statement if the JDBC driver does not support batch updates.

Parameters:
sql - defining an array of SQL statements that will be executed.
Returns:
an array of the number of rows affected by each statement
Throws:
DataAccessException - if there is any problem executing the batch

execute

<T> T execute(PreparedStatementCreator psc,
              PreparedStatementCallback<T> action)
          throws DataAccessException
Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement. This allows for implementing arbitrary data access operations on a single Statement, within Spring's managed JDBC environment: that is, participating in Spring-managed transactions and converting JDBC SQLExceptions into Spring's DataAccessException hierarchy.

The callback action can return a result object, for example a domain object or a collection of domain objects.

Parameters:
psc - object that can create a PreparedStatement given a Connection
action - callback object that specifies the action
Returns:
a result object returned by the action, or null
Throws:
DataAccessException - if there is any problem

execute

<T> T execute(java.lang.String sql,
              PreparedStatementCallback<T> action)
          throws DataAccessException
Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement. This allows for implementing arbitrary data access operations on a single Statement, within Spring's managed JDBC environment: that is, participating in Spring-managed transactions and converting JDBC SQLExceptions into Spring's DataAccessException hierarchy.

The callback action can return a result object, for example a domain object or a collection of domain objects.

Parameters:
sql - SQL to execute
action - callback object that specifies the action
Returns:
a result object returned by the action, or null
Throws:
DataAccessException - if there is any problem

query

<T> T query(PreparedStatementCreator psc,
            ResultSetExtractor<T> rse)
        throws DataAccessException
Query using a prepared statement, reading the ResultSet with a ResultSetExtractor.

A PreparedStatementCreator can either be implemented directly or configured through a PreparedStatementCreatorFactory.

Parameters:
psc - object that can create a PreparedStatement given a Connection
rse - object that will extract results
Returns:
an arbitrary result object, as returned by the ResultSetExtractor
Throws:
DataAccessException - if there is any problem
See Also:
PreparedStatementCreatorFactory

query

<T> T query(java.lang.String sql,
            PreparedStatementSetter pss,
            ResultSetExtractor<T> rse)
        throws DataAccessException
Query using a prepared statement, reading the ResultSet with a ResultSetExtractor.

Parameters:
sql - SQL query to execute
pss - object that knows how to set values on the prepared statement. If this is null, the SQL will be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to set fetch size and other performance options.
rse - object that will extract results
Returns:
an arbitrary result object, as returned by the ResultSetExtractor
Throws:
DataAccessException - if there is any problem

query

<T> T query(java.lang.String sql,
            java.lang.Object[] args,
            int[] argTypes,
            ResultSetExtractor<T> rse)
        throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, reading the ResultSet with a ResultSetExtractor.

Parameters:
sql - SQL query to execute
args - arguments to bind to the query
argTypes - SQL types of the arguments (constants from java.sql.Types)
rse - object that will extract results
Returns:
an arbitrary result object, as returned by the ResultSetExtractor
Throws:
DataAccessException - if the query fails
See Also:
Types

query

<T> T query(java.lang.String sql,
            java.lang.Object[] args,
            ResultSetExtractor<T> rse)
        throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, reading the ResultSet with a ResultSetExtractor.

Parameters:
sql - SQL query to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
rse - object that will extract results
Returns:
an arbitrary result object, as returned by the ResultSetExtractor
Throws:
DataAccessException - if the query fails

query

<T> T query(java.lang.String sql,
            ResultSetExtractor<T> rse,
            java.lang.Object... args)
        throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, reading the ResultSet with a ResultSetExtractor.

Parameters:
sql - SQL query to execute
rse - object that will extract results
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
Returns:
an arbitrary result object, as returned by the ResultSetExtractor
Throws:
DataAccessException - if the query fails

query

void query(PreparedStatementCreator psc,
           RowCallbackHandler rch)
           throws DataAccessException
Query using a prepared statement, reading the ResultSet on a per-row basis with a RowCallbackHandler.

A PreparedStatementCreator can either be implemented directly or configured through a PreparedStatementCreatorFactory.

Parameters:
psc - object that can create a PreparedStatement given a Connection
rch - object that will extract results, one row at a time
Throws:
DataAccessException - if there is any problem
See Also:
PreparedStatementCreatorFactory

query

void query(java.lang.String sql,
           PreparedStatementSetter pss,
           RowCallbackHandler rch)
           throws DataAccessException
Query given SQL to create a prepared statement from SQL and a PreparedStatementSetter implementation that knows how to bind values to the query, reading the ResultSet on a per-row basis with a RowCallbackHandler.

Parameters:
sql - SQL query to execute
pss - object that knows how to set values on the prepared statement. If this is null, the SQL will be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to set fetch size and other performance options.
rch - object that will extract results, one row at a time
Throws:
DataAccessException - if the query fails

query

void query(java.lang.String sql,
           java.lang.Object[] args,
           int[] argTypes,
           RowCallbackHandler rch)
           throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, reading the ResultSet on a per-row basis with a RowCallbackHandler.

Parameters:
sql - SQL query to execute
args - arguments to bind to the query
argTypes - SQL types of the arguments (constants from java.sql.Types)
rch - object that will extract results, one row at a time
Throws:
DataAccessException - if the query fails
See Also:
Types

query

void query(java.lang.String sql,
           java.lang.Object[] args,
           RowCallbackHandler rch)
           throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, reading the ResultSet on a per-row basis with a RowCallbackHandler.

Parameters:
sql - SQL query to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
rch - object that will extract results, one row at a time
Throws:
DataAccessException - if the query fails

query

void query(java.lang.String sql,
           RowCallbackHandler rch,
           java.lang.Object... args)
           throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, reading the ResultSet on a per-row basis with a RowCallbackHandler.

Parameters:
sql - SQL query to execute
rch - object that will extract results, one row at a time
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
Throws:
DataAccessException - if the query fails

query

<T> java.util.List<T> query(PreparedStatementCreator psc,
                            RowMapper<T> rowMapper)
                        throws DataAccessException
Query using a prepared statement, mapping each row to a Java object via a RowMapper.

A PreparedStatementCreator can either be implemented directly or configured through a PreparedStatementCreatorFactory.

Parameters:
psc - object that can create a PreparedStatement given a Connection
rowMapper - object that will map one object per row
Returns:
the result List, containing mapped objects
Throws:
DataAccessException - if there is any problem
See Also:
PreparedStatementCreatorFactory

query

<T> java.util.List<T> query(java.lang.String sql,
                            PreparedStatementSetter pss,
                            RowMapper<T> rowMapper)
                        throws DataAccessException
Query given SQL to create a prepared statement from SQL and a PreparedStatementSetter implementation that knows how to bind values to the query, mapping each row to a Java object via a RowMapper.

Parameters:
sql - SQL query to execute
pss - object that knows how to set values on the prepared statement. If this is null, the SQL will be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to set fetch size and other performance options.
rowMapper - object that will map one object per row
Returns:
the result List, containing mapped objects
Throws:
DataAccessException - if the query fails

query

<T> java.util.List<T> query(java.lang.String sql,
                            java.lang.Object[] args,
                            int[] argTypes,
                            RowMapper<T> rowMapper)
                        throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping each row to a Java object via a RowMapper.

Parameters:
sql - SQL query to execute
args - arguments to bind to the query
argTypes - SQL types of the arguments (constants from java.sql.Types)
rowMapper - object that will map one object per row
Returns:
the result List, containing mapped objects
Throws:
DataAccessException - if the query fails
See Also:
Types

query

<T> java.util.List<T> query(java.lang.String sql,
                            java.lang.Object[] args,
                            RowMapper<T> rowMapper)
                        throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping each row to a Java object via a RowMapper.

Parameters:
sql - SQL query to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
rowMapper - object that will map one object per row
Returns:
the result List, containing mapped objects
Throws:
DataAccessException - if the query fails

query

<T> java.util.List<T> query(java.lang.String sql,
                            RowMapper<T> rowMapper,
                            java.lang.Object... args)
                        throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping each row to a Java object via a RowMapper.

Parameters:
sql - SQL query to execute
rowMapper - object that will map one object per row
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
Returns:
the result List, containing mapped objects
Throws:
DataAccessException - if the query fails

queryForObject

<T> T queryForObject(java.lang.String sql,
                     java.lang.Object[] args,
                     int[] argTypes,
                     RowMapper<T> rowMapper)
                 throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping a single result row to a Java object via a RowMapper.

Parameters:
sql - SQL query to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
argTypes - SQL types of the arguments (constants from java.sql.Types)
rowMapper - object that will map one object per row
Returns:
the single mapped object
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row
DataAccessException - if the query fails

queryForObject

<T> T queryForObject(java.lang.String sql,
                     java.lang.Object[] args,
                     RowMapper<T> rowMapper)
                 throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping a single result row to a Java object via a RowMapper.

Parameters:
sql - SQL query to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
rowMapper - object that will map one object per row
Returns:
the single mapped object
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row
DataAccessException - if the query fails

queryForObject

<T> T queryForObject(java.lang.String sql,
                     RowMapper<T> rowMapper,
                     java.lang.Object... args)
                 throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping a single result row to a Java object via a RowMapper.

Parameters:
sql - SQL query to execute
rowMapper - object that will map one object per row
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
Returns:
the single mapped object
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row
DataAccessException - if the query fails

queryForObject

<T> T queryForObject(java.lang.String sql,
                     java.lang.Object[] args,
                     int[] argTypes,
                     java.lang.Class<T> requiredType)
                 throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result object.

The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.

Parameters:
sql - SQL query to execute
args - arguments to bind to the query
argTypes - SQL types of the arguments (constants from java.sql.Types)
requiredType - the type that the result object is expected to match
Returns:
the result object of the required type, or null in case of SQL NULL
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row
DataAccessException - if the query fails
See Also:
queryForObject(String, Class), Types

queryForObject

<T> T queryForObject(java.lang.String sql,
                     java.lang.Object[] args,
                     java.lang.Class<T> requiredType)
                 throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result object.

The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.

Parameters:
sql - SQL query to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
requiredType - the type that the result object is expected to match
Returns:
the result object of the required type, or null in case of SQL NULL
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row
DataAccessException - if the query fails
See Also:
queryForObject(String, Class)

queryForObject

<T> T queryForObject(java.lang.String sql,
                     java.lang.Class<T> requiredType,
                     java.lang.Object... args)
                 throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result object.

The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.

Parameters:
sql - SQL query to execute
requiredType - the type that the result object is expected to match
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
Returns:
the result object of the required type, or null in case of SQL NULL
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row
DataAccessException - if the query fails
See Also:
queryForObject(String, Class)

queryForMap

java.util.Map<java.lang.String,java.lang.Object> queryForMap(java.lang.String sql,
                                                             java.lang.Object[] args,
                                                             int[] argTypes)
                                                             throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result Map.

The query is expected to be a single row query; the result row will be mapped to a Map (one entry for each column, using the column name as the key).

Parameters:
sql - SQL query to execute
args - arguments to bind to the query
argTypes - SQL types of the arguments (constants from java.sql.Types)
Returns:
the result Map (one entry for each column, using the column name as the key)
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row
DataAccessException - if the query fails
See Also:
queryForMap(String), ColumnMapRowMapper, Types

queryForMap

java.util.Map<java.lang.String,java.lang.Object> queryForMap(java.lang.String sql,
                                                             java.lang.Object... args)
                                                             throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result Map. The queryForMap() methods defined by this interface are appropriate when you don't have a domain model. Otherwise, consider using one of the queryForObject() methods.

The query is expected to be a single row query; the result row will be mapped to a Map (one entry for each column, using the column name as the key).

Parameters:
sql - SQL query to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
Returns:
the result Map (one entry for each column, using the column name as the key)
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row
DataAccessException - if the query fails
See Also:
queryForMap(String), ColumnMapRowMapper

queryForLong

long queryForLong(java.lang.String sql,
                  java.lang.Object[] args,
                  int[] argTypes)
                  throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, resulting in a long value.

The query is expected to be a single row/single column query that results in a long value.

Parameters:
sql - SQL query to execute
args - arguments to bind to the query
argTypes - SQL types of the arguments (constants from java.sql.Types)
Returns:
the long value, or 0 in case of SQL NULL
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row
DataAccessException - if the query fails
See Also:
queryForLong(String), Types

queryForLong

long queryForLong(java.lang.String sql,
                  java.lang.Object... args)
                  throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, resulting in a long value.

The query is expected to be a single row/single column query that results in a long value.

Parameters:
sql - SQL query to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
Returns:
the long value, or 0 in case of SQL NULL
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row
DataAccessException - if the query fails
See Also:
queryForLong(String)

queryForInt

int queryForInt(java.lang.String sql,
                java.lang.Object[] args,
                int[] argTypes)
                throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, resulting in an int value.

The query is expected to be a single row/single column query that results in an int value.

Parameters:
sql - SQL query to execute
args - arguments to bind to the query
argTypes - SQL types of the arguments (constants from java.sql.Types)
Returns:
the int value, or 0 in case of SQL NULL
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row
DataAccessException - if the query fails
See Also:
queryForInt(String), Types

queryForInt

int queryForInt(java.lang.String sql,
                java.lang.Object... args)
                throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, resulting in an int value.

The query is expected to be a single row/single column query that results in an int value.

Parameters:
sql - SQL query to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
Returns:
the int value, or 0 in case of SQL NULL
Throws:
IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row
DataAccessException - if the query fails
See Also:
queryForInt(String)

queryForList

<T> java.util.List<T> queryForList(java.lang.String sql,
                                   java.lang.Object[] args,
                                   int[] argTypes,
                                   java.lang.Class<T> elementType)
                               throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.

The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.

Parameters:
sql - SQL query to execute
args - arguments to bind to the query
argTypes - SQL types of the arguments (constants from java.sql.Types)
elementType - the required type of element in the result list (for example, Integer.class)
Returns:
a List of objects that match the specified element type
Throws:
DataAccessException - if the query fails
See Also:
queryForList(String, Class), SingleColumnRowMapper

queryForList

<T> java.util.List<T> queryForList(java.lang.String sql,
                                   java.lang.Object[] args,
                                   java.lang.Class<T> elementType)
                               throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.

The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.

Parameters:
sql - SQL query to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
elementType - the required type of element in the result list (for example, Integer.class)
Returns:
a List of objects that match the specified element type
Throws:
DataAccessException - if the query fails
See Also:
queryForList(String, Class), SingleColumnRowMapper

queryForList

<T> java.util.List<T> queryForList(java.lang.String sql,
                                   java.lang.Class<T> elementType,
                                   java.lang.Object... args)
                               throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.

The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.

Parameters:
sql - SQL query to execute
elementType - the required type of element in the result list (for example, Integer.class)
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
Returns:
a List of objects that match the specified element type
Throws:
DataAccessException - if the query fails
See Also:
queryForList(String, Class), SingleColumnRowMapper

queryForList

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
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.

The results will be mapped to a List (one entry for each row) of Maps (one entry for each column, using the column name as the key). Thus Each element in the list will be of the form returned by this interface's queryForMap() methods.

Parameters:
sql - SQL query to execute
args - arguments to bind to the query
argTypes - SQL types of the arguments (constants from java.sql.Types)
Returns:
a List that contains a Map per row
Throws:
DataAccessException - if the query fails
See Also:
queryForList(String), Types

queryForList

java.util.List<java.util.Map<java.lang.String,java.lang.Object>> queryForList(java.lang.String sql,
                                                                              java.lang.Object... args)
                                                                              throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.

The results will be mapped to a List (one entry for each row) of Maps (one entry for each column, using the column name as the key). Each element in the list will be of the form returned by this interface's queryForMap() methods.

Parameters:
sql - SQL query to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
Returns:
a List that contains a Map per row
Throws:
DataAccessException - if the query fails
See Also:
queryForList(String)

queryForRowSet

SqlRowSet queryForRowSet(java.lang.String sql,
                         java.lang.Object[] args,
                         int[] argTypes)
                         throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a SqlRowSet.

The results will be mapped to an SqlRowSet which holds the data in a disconnected fashion. This wrapper will translate any SQLExceptions thrown.

Note that that, for the default implementation, JDBC RowSet support needs to be available at runtime: by default, Sun's com.sun.rowset.CachedRowSetImpl class is used, which is part of JDK 1.5+ and also available separately as part of Sun's JDBC RowSet Implementations download (rowset.jar).

Parameters:
sql - SQL query to execute
args - arguments to bind to the query
argTypes - SQL types of the arguments (constants from java.sql.Types)
Returns:
a SqlRowSet representation (possibly a wrapper around a javax.sql.rowset.CachedRowSet)
Throws:
DataAccessException - if there is any problem executing the query
See Also:
queryForRowSet(String), SqlRowSetResultSetExtractor, CachedRowSet, Types

queryForRowSet

SqlRowSet queryForRowSet(java.lang.String sql,
                         java.lang.Object... args)
                         throws DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a SqlRowSet.

The results will be mapped to an SqlRowSet which holds the data in a disconnected fashion. This wrapper will translate any SQLExceptions thrown.

Note that that, for the default implementation, JDBC RowSet support needs to be available at runtime: by default, Sun's com.sun.rowset.CachedRowSetImpl class is used, which is part of JDK 1.5+ and also available separately as part of Sun's JDBC RowSet Implementations download (rowset.jar).

Parameters:
sql - SQL query to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
Returns:
a SqlRowSet representation (possibly a wrapper around a javax.sql.rowset.CachedRowSet)
Throws:
DataAccessException - if there is any problem executing the query
See Also:
queryForRowSet(String), SqlRowSetResultSetExtractor, CachedRowSet

update

int update(PreparedStatementCreator psc)
           throws DataAccessException
Issue a single SQL update operation (such as an insert, update or delete statement) using a PreparedStatementCreator to provide SQL and any required parameters.

A PreparedStatementCreator can either be implemented directly or configured through a PreparedStatementCreatorFactory.

Parameters:
psc - object that provides SQL and any necessary parameters
Returns:
the number of rows affected
Throws:
DataAccessException - if there is any problem issuing the update
See Also:
PreparedStatementCreatorFactory

update

int update(PreparedStatementCreator psc,
           KeyHolder generatedKeyHolder)
           throws DataAccessException
Issue an update statement using a PreparedStatementCreator to provide SQL and any required parameters. Generated keys will be put into the given KeyHolder.

Note that the given PreparedStatementCreator has to create a statement with activated extraction of generated keys (a JDBC 3.0 feature). This can either be done directly or through using a PreparedStatementCreatorFactory.

Parameters:
psc - object that provides SQL and any necessary parameters
generatedKeyHolder - KeyHolder that will hold the generated keys
Returns:
the number of rows affected
Throws:
DataAccessException - if there is any problem issuing the update
See Also:
PreparedStatementCreatorFactory, GeneratedKeyHolder

update

int update(java.lang.String sql,
           PreparedStatementSetter pss)
           throws DataAccessException
Issue an update statement using a PreparedStatementSetter to set bind parameters, with given SQL. Simpler than using a PreparedStatementCreator as this method will create the PreparedStatement: The PreparedStatementSetter just needs to set parameters.

Parameters:
sql - SQL containing bind parameters
pss - helper that sets bind parameters. If this is null we run an update with static SQL.
Returns:
the number of rows affected
Throws:
DataAccessException - if there is any problem issuing the update

update

int update(java.lang.String sql,
           java.lang.Object[] args,
           int[] argTypes)
           throws DataAccessException
Issue a single SQL update operation (such as an insert, update or delete statement) via a prepared statement, binding the given arguments.

Parameters:
sql - SQL containing bind parameters
args - arguments to bind to the query
argTypes - SQL types of the arguments (constants from java.sql.Types)
Returns:
the number of rows affected
Throws:
DataAccessException - if there is any problem issuing the update
See Also:
Types

update

int update(java.lang.String sql,
           java.lang.Object... args)
           throws DataAccessException
Issue a single SQL update operation (such as an insert, update or delete statement) via a prepared statement, binding the given arguments.

Parameters:
sql - SQL containing bind parameters
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
Returns:
the number of rows affected
Throws:
DataAccessException - if there is any problem issuing the update

batchUpdate

int[] batchUpdate(java.lang.String sql,
                  BatchPreparedStatementSetter pss)
                  throws DataAccessException
Issue multiple update statements on a single PreparedStatement, using batch updates and a BatchPreparedStatementSetter to set values.

Will fall back to separate updates on a single PreparedStatement if the JDBC driver does not support batch updates.

Parameters:
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
Returns:
an array of the number of rows affected by each statement
Throws:
DataAccessException - if there is any problem issuing the update

batchUpdate

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.

Parameters:
sql - the SQL statement to execute
batchArgs - the List of Object arrays containing the batch of arguments for the query
Returns:
an array containing the numbers of rows affected by each update in the batch

batchUpdate

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.

Parameters:
sql - the SQL statement to execute.
batchArgs - the List of Object arrays containing the batch of arguments for the query
argTypes - SQL types of the arguments (constants from java.sql.Types)
Returns:
an array containing the numbers of rows affected by each update in the batch

batchUpdate

<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. The arguments' values will be set using the ParameterizedPreparedStatementSetter. Each batch should be of size indicated in 'batchSize'.

Parameters:
sql - the SQL statement to execute.
batchArgs - the List of Object arrays containing the batch of arguments for the query
batchSize - batch size
pss - ParameterizedPreparedStatementSetter to use
Returns:
an array containing for each batch another array containing the numbers of rows affected by each update in the batch

execute

<T> T execute(CallableStatementCreator csc,
              CallableStatementCallback<T> action)
          throws DataAccessException
Execute a JDBC data access operation, implemented as callback action working on a JDBC CallableStatement. This allows for implementing arbitrary data access operations on a single Statement, within Spring's managed JDBC environment: that is, participating in Spring-managed transactions and converting JDBC SQLExceptions into Spring's DataAccessException hierarchy.

The callback action can return a result object, for example a domain object or a collection of domain objects.

Parameters:
csc - object that can create a CallableStatement given a Connection
action - callback object that specifies the action
Returns:
a result object returned by the action, or null
Throws:
DataAccessException - if there is any problem

execute

<T> T execute(java.lang.String callString,
              CallableStatementCallback<T> action)
          throws DataAccessException
Execute a JDBC data access operation, implemented as callback action working on a JDBC CallableStatement. This allows for implementing arbitrary data access operations on a single Statement, within Spring's managed JDBC environment: that is, participating in Spring-managed transactions and converting JDBC SQLExceptions into Spring's DataAccessException hierarchy.

The callback action can return a result object, for example a domain object or a collection of domain objects.

Parameters:
callString - the SQL call string to execute
action - callback object that specifies the action
Returns:
a result object returned by the action, or null
Throws:
DataAccessException - if there is any problem

call

java.util.Map<java.lang.String,java.lang.Object> call(CallableStatementCreator csc,
                                                      java.util.List<SqlParameter> declaredParameters)
                                                      throws DataAccessException
Execute a SQL call using a CallableStatementCreator to provide SQL and any required parameters.

Parameters:
csc - object that provides SQL and any necessary parameters
declaredParameters - list of declared SqlParameter objects
Returns:
Map of extracted out parameters
Throws:
DataAccessException - if there is any problem issuing the update

Spring Framework