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.

Version:
$Id: JdbcOperations.java,v 1.7 2004/03/18 02:46:08 trisberg Exp $
Author:
Rod Johnson, Juergen Hoeller
See Also:
JdbcTemplate

Method Summary
 int[] batchUpdate(java.lang.String sql, BatchPreparedStatementSetter pss)
          Issue multiple updates on a single PreparedStatement, using JDBC 2.0 batch updates and a BatchPreparedStatementSetter to set values.
 java.util.Map call(CallableStatementCreator csc, java.util.List declaredParameters)
          Execute a SQL call using a CallableStatementCreator to provide SQL and any required parameters.
 java.lang.Object execute(CallableStatementCreator csc, CallableStatementCallback action)
          Execute the action specified by the given action object within a JDBC CallableStatement.
 java.lang.Object execute(PreparedStatementCreator psc, PreparedStatementCallback action)
          Execute the action specified by the given action object within a JDBC PreparedStatement.
 java.lang.Object execute(StatementCallback action)
          Execute the action specified by the given action object within a JDBC Statement.
 void execute(java.lang.String sql)
          Issue a single SQL execute, typically a DDL statement.
 java.lang.Object execute(java.lang.String callString, CallableStatementCallback action)
          Execute the action specified by the given action object within a JDBC CallableStatement.
 java.lang.Object execute(java.lang.String sql, PreparedStatementCallback action)
          Execute the action specified by the given action object within a JDBC PreparedStatement.
 java.lang.Object query(PreparedStatementCreator psc, ResultSetExtractor rse)
          Query using a prepared statement.
 java.util.List query(PreparedStatementCreator psc, RowCallbackHandler rch)
          Query using a prepared statement, reading the ResultSet on a per-row basis with a RowCallbackHandler (potentially implementing the ResultReader sub-interface that provides a result List).
 java.util.List 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 (potentially implementing the ResultReader sub-interface that provides a result List).
 java.util.List 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 (potentially implementing the ResultReader sub-interface that provides a result List).
 java.lang.Object query(java.lang.String sql, PreparedStatementSetter pss, ResultSetExtractor rse)
          Query using a prepared statement, reading the ResultSet with a ResultSetExtractor.
 java.util.List 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 (potentially implementing the ResultReader sub-interface that provides a result List).
 java.lang.Object query(java.lang.String sql, ResultSetExtractor rse)
          Execute a query given static SQL, reading the ResultSet with a ResultSetExtractor.
 java.util.List query(java.lang.String sql, RowCallbackHandler rch)
          Execute a query given static SQL, reading the ResultSet on a per-row basis with a RowCallbackHandler (potentially implementing the ResultReader sub-interface that provides a result List).
 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.
 java.util.List queryForList(java.lang.String sql)
          Execute a query for a result list, given static SQL.
 java.util.List 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.
 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.
 java.lang.Object queryForObject(java.lang.String sql, java.lang.Class requiredType)
          Execute a query for a result object, given static SQL.
 java.lang.Object queryForObject(java.lang.String sql, java.lang.Object[] args, java.lang.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.
 int update(PreparedStatementCreator psc)
          Issue an update using a PreparedStatementCreator to provide SQL and any required parameters.
 int update(java.lang.String sql)
          Issue a single SQL update.
 int update(java.lang.String sql, java.lang.Object[] args)
          Issue an update via a prepared statement, binding the given arguments.
 int update(java.lang.String sql, java.lang.Object[] args, int[] argTypes)
          Issue an update via a prepared statement, binding the given arguments.
 int update(java.lang.String sql, PreparedStatementSetter pss)
          Issue an update using a PreparedStatementSetter to set bind parameters, with given SQL.
 

Method Detail

execute

public java.lang.Object execute(StatementCallback action)
                         throws DataAccessException
Execute the action specified by the given action object within a JDBC Statement. Allows for returning a result object, i.e. 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

public 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

public java.lang.Object query(java.lang.String sql,
                              ResultSetExtractor 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 a null PreparedStatementSetter as a parameter.

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, PreparedStatementSetter, ResultSetExtractor)

query

public java.util.List 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 (potentially implementing the ResultReader sub-interface that provides a result List).

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 PreparedStatementSetter argument.

Parameters:
sql - SQL query to execute
rch - object that will extract results
Returns:
the result List in case of a ResultReader, or null else
Throws:
DataAccessException - if there is any problem executing the query
See Also:
query(String, PreparedStatementSetter, RowCallbackHandler)

queryForList

public java.util.List 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.

This method is useful for running static SQL with a known outcome. The results will be mapped to an ArrayList (one entry for each row) of HashMaps (one entry for each column using the column name as the key).

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

queryForObject

public java.lang.Object queryForObject(java.lang.String sql,
                                       java.lang.Class 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
Throws:
DataAccessException - if there is any problem executing the query
See Also:
queryForObject(String, Object[], Class)

queryForLong

public 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
Throws:
DataAccessException - if there is any problem executing the query
See Also:
queryForLong(String, Object[])

queryForInt

public 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
Throws:
DataAccessException - if there is any problem executing the query
See Also:
queryForInt(String, Object[])

update

public int update(java.lang.String sql)
           throws 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.

execute

public java.lang.Object execute(PreparedStatementCreator psc,
                                PreparedStatementCallback action)
Execute the action specified by the given action object within a JDBC PreparedStatement. Allows for returning a result object, i.e. 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

public java.lang.Object execute(java.lang.String sql,
                                PreparedStatementCallback action)
Execute the action specified by the given action object within a JDBC PreparedStatement. Allows for returning a result object, i.e. 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

public java.lang.Object query(PreparedStatementCreator psc,
                              ResultSetExtractor rse)
Query using a prepared statement.

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

query

public java.lang.Object query(java.lang.String sql,
                              PreparedStatementSetter pss,
                              ResultSetExtractor rse)
Query using a prepared statement, reading the ResultSet with a ResultSetExtractor.

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.
rse - object that will extract results.
Returns:
an arbitrary result object, as returned by the ResultSetExtractor
Throws:
DataAccessException - if there is any problem

query

public java.util.List query(PreparedStatementCreator psc,
                            RowCallbackHandler rch)
                     throws DataAccessException
Query using a prepared statement, reading the ResultSet on a per-row basis with a RowCallbackHandler (potentially implementing the ResultReader sub-interface that provides a result List).

Parameters:
psc - object that can create a PreparedStatement given a Connection
rch - object that will extract results, one row at a time
Returns:
the result List in case of a ResultReader, or null else
Throws:
DataAccessException - if there is any problem

query

public java.util.List 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 (potentially implementing the ResultReader sub-interface that provides a result List).

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.
rch - object that will extract results
Returns:
the result List in case of a ResultReader, or null else
Throws:
DataAccessException - if the query fails

query

public java.util.List 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 (potentially implementing the ResultReader sub-interface that provides a result List).

Parameters:
sql - SQL 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
Returns:
the result List in case of a ResultReader, or null else
Throws:
DataAccessException - if the query fails
See Also:
Types

query

public java.util.List 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 (potentially implementing the ResultReader sub-interface that provides a result List).

Parameters:
sql - SQL to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the respective SQL type)
rch - object that will extract results
Returns:
the result List in case of a ResultReader, or null else
Throws:
DataAccessException - if the query fails

queryForList

public java.util.List 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.

This method is useful for running static SQL with a known outcome. The results will be mapped to an ArrayList (one entry for each row) of HashMaps (one entry for each column using the column name as the key).

Parameters:
sql - SQL to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the respective SQL type)
Returns:
an ArrayList that contains a HashMap per row
Throws:
DataAccessException - if the query fails
See Also:
queryForList(String)

queryForObject

public java.lang.Object queryForObject(java.lang.String sql,
                                       java.lang.Object[] args,
                                       java.lang.Class 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.

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 to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the respective SQL type)
requiredType - the type that the result object is expected to match
Returns:
the result object of the required type
Throws:
DataAccessException - if the query fails
See Also:
queryForObject(String, Class)

queryForLong

public 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.

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 to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the respective SQL type)
Returns:
the long value
Throws:
DataAccessException - if the query fails
See Also:
queryForLong(String)

queryForInt

public 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.

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 to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the respective SQL type)
Returns:
the int value
Throws:
DataAccessException - if the query fails
See Also:
queryForInt(String)

update

public int update(PreparedStatementCreator psc)
           throws DataAccessException
Issue an update using a PreparedStatementCreator to provide SQL and any required parameters.

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

update

public int update(java.lang.String sql,
                  PreparedStatementSetter pss)
           throws 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 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

public int update(java.lang.String sql,
                  java.lang.Object[] args,
                  int[] argTypes)
           throws DataAccessException
Issue an update 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

update

public int update(java.lang.String sql,
                  java.lang.Object[] args)
           throws DataAccessException
Issue an update 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 respective SQL type)
Returns:
the number of rows affected
Throws:
DataAccessException - if there is any problem issuing the update

batchUpdate

public int[] batchUpdate(java.lang.String sql,
                         BatchPreparedStatementSetter pss)
                  throws DataAccessException
Issue multiple updates on a single PreparedStatement, using JDBC 2.0 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

execute

public java.lang.Object execute(CallableStatementCreator csc,
                                CallableStatementCallback action)
Execute the action specified by the given action object within a JDBC CallableStatement. Allows for returning a result object, i.e. 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

public java.lang.Object execute(java.lang.String callString,
                                CallableStatementCallback action)
Execute the action specified by the given action object within a JDBC CallableStatement. Allows for returning a result object, i.e. 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

public java.util.Map call(CallableStatementCreator csc,
                          java.util.List 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
Returns:
Map of extracted out parameters
Throws:
DataAccessException - if there is any problem issuing the update


Copyright (C) 2003-2004 The Spring Framework Project.