org.springframework.jdbc.core
Interface JdbcOperations

All Known Implementing Classes:
JdbcTemplate

public interface JdbcOperations

Interface that specifies a basic set of JDBC operations. Implemented by JdbcTemplate. Not often used, 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.

Author:
Rod Johnson
Version: $Id: JdbcOperations.java,v 1.1 2004/02/07 00:12:39 jhoeller Exp $
See Also: JdbcTemplate

Method Summary
 int[]batchUpdate(String sql, BatchPreparedStatementSetter setter)
          Issue multiple updates using JDBC 2.0 batch updates and PreparedStatementSetters to set values on a PreparedStatement created by this method
 voiddoWithResultSetFromPreparedQuery(PreparedStatementCreator psc, ResultSetExtractor rse)
          Query using a prepared statement.
 voiddoWithResultSetFromStaticQuery(String sql, ResultSetExtractor rse)
          Execute a query given static SQL.
 Mapexecute(CallableStatementCreator csc, List declaredParameters)
          Execute an Sql call using a CallableStatementCreator to provide SQL and any required parameters
 voidquery(String sql, RowCallbackHandler callbackHandler)
          Execute a query given static SQL.
 voidquery(PreparedStatementCreator psc, RowCallbackHandler callbackHandler)
          Query using a prepared statement.
 voidquery(String sql, PreparedStatementSetter pss, RowCallbackHandler callbackHandler)
          Query given SQL to create a prepared statement from SQL and a PreparedStatementSetter implementation that knows how to bind values to the query.
 intupdate(String sql)
          Issue a single SQL update.
 intupdate(PreparedStatementCreator psc)
          Issue an update using a PreparedStatementCreator to provide SQL and any required parameters
 int[]update(PreparedStatementCreator[] pscs)
          Issue multiple updates using multiple PreparedStatementCreators to provide SQL and any required parameters.
 intupdate(String sql, PreparedStatementSetter pss)
          Issue an update using a PreparedStatementSetter to set bind parameters, with given SQL.

Method Detail

batchUpdate

public int[] batchUpdate(String sql, BatchPreparedStatementSetter setter)
throws org.springframework.dao.DataAccessException
Issue multiple updates using JDBC 2.0 batch updates and PreparedStatementSetters to set values on a PreparedStatement created by this method
Parameters:
sql - defining PreparedStatement that will be reused. All statements in the batch will use the same SQL.
setter - 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

doWithResultSetFromPreparedQuery

public void doWithResultSetFromPreparedQuery(PreparedStatementCreator psc, ResultSetExtractor rse)
throws org.springframework.dao.DataAccessException
Query using a prepared statement. Most other query methods use this method.
Parameters:
psc - Callback handler that can create a PreparedStatement given a Connection
rse - object that will extract results.
Throws:
DataAccessException - if there is any problem

doWithResultSetFromStaticQuery

public void doWithResultSetFromStaticQuery(String sql, ResultSetExtractor rse)
throws org.springframework.dao.DataAccessException
Execute a query given static SQL. Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded query method with a NOP PreparedStatement setter as a parameter.
Parameters:
sql - SQL query to execute
rse - object that will extract all rows of results
Throws:
DataAccessException - if there is any problem executing the query

execute

public Map execute(CallableStatementCreator csc, List declaredParameters)
throws org.springframework.dao.DataAccessException
Execute an Sql call using a CallableStatementCreator to provide SQL and any required parameters
Parameters:
csc - helper: callback object that provides SQL and any necessary parameters
Returns: Map of extracted out parameters
Throws:
DataAccessException - if there is any problem issuing the update

query

public void query(String sql, RowCallbackHandler callbackHandler)
throws org.springframework.dao.DataAccessException
Execute a query given static SQL.

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

In most cases the query() method should be preferred to the parallel doWithResultSetXXXX() method. The doWithResultSetXXXX() methods are included to allow full control over the extraction of data from ResultSets and to facilitate integration with third-party software.

Parameters:
sql - SQL query to execute
callbackHandler - object that will extract results
Throws:
DataAccessException - if there is any problem executing the query
See Also:
query(java.lang.String,org.springframework.jdbc.core.PreparedStatementSetter,org.springframework.jdbc.core.RowCallbackHandler)

query

public void query(PreparedStatementCreator psc, RowCallbackHandler callbackHandler)
throws org.springframework.dao.DataAccessException
Query using a prepared statement.
Parameters:
psc - Callback handler that can create a PreparedStatement given a Connection
callbackHandler - object that will extract results, one row at a time
Throws:
DataAccessException - if there is any problem

query

public void query(String sql, PreparedStatementSetter pss, RowCallbackHandler callbackHandler)
throws org.springframework.dao.DataAccessException
Query given SQL to create a prepared statement from SQL and a PreparedStatementSetter implementation that knows how to bind values to the query.
Parameters:
sql - SQL 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.
callbackHandler - object that will extract results
Throws:
DataAccessException - if the query fails

update

public int update(String sql)
throws org.springframework.dao.DataAccessException
Issue a single SQL update.
Parameters:
sql - static SQL to execute
Returns: the number of rows affected
Throws:
DataAccessException - if there is any problem.

update

public int update(PreparedStatementCreator psc)
throws org.springframework.dao.DataAccessException
Issue an update using a PreparedStatementCreator to provide SQL and any required parameters
Parameters:
psc - helper: callback object that provides SQL and any necessary parameters
Returns: the number of rows affected
Throws:
DataAccessException - if there is any problem issuing the update

update

public int[] update(PreparedStatementCreator[] pscs)
throws org.springframework.dao.DataAccessException
Issue multiple updates using multiple PreparedStatementCreators to provide SQL and any required parameters.
Parameters:
pscs - array of callback objects that provide SQL and any necessary parameters
Returns: an array of the number of rows affected by each statement
Throws:
DataAccessException - if there is any problem issuing the update

update

public int update(String sql, PreparedStatementSetter pss)
throws org.springframework.dao.DataAccessException
Issue an update using a PreparedStatementSetter to set bind parameters, with given SQL. Simpler than using a PreparedStatementCreator as this method will create the PreparedStatement: the PreparedStatementSetter has only 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