📄 jdbcoperations.java
字号:
*/
Map queryForMap(String sql, 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.
* <p>The query is expected to be a single row/single column query that
* results in a long value.
* @param sql SQL query to execute
* @param args arguments to bind to the query
* @param argTypes SQL types of the arguments
* (constants from <code>java.sql.Types</code>)
* @return 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
* @throws DataAccessException if the query fails
* @see #queryForLong(String)
* @see java.sql.Types
*/
long queryForLong(String sql, 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.
* <p>The query is expected to be a single row/single column query that
* results in a long value.
* @param sql SQL query to execute
* @param args arguments to bind to the query
* (leaving it to the PreparedStatement to guess the corresponding SQL type)
* @return 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
* @throws DataAccessException if the query fails
* @see #queryForLong(String)
*/
long queryForLong(String sql, 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.
* <p>The query is expected to be a single row/single column query that
* results in an int value.
* @param sql SQL query to execute
* @param args arguments to bind to the query
* @param argTypes SQL types of the arguments
* (constants from <code>java.sql.Types</code>)
* @return 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
* @throws DataAccessException if the query fails
* @see #queryForInt(String)
* @see java.sql.Types
*/
int queryForInt(String sql, 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.
* <p>The query is expected to be a single row/single column query that
* results in an int value.
* @param sql SQL query to execute
* @param args arguments to bind to the query
* (leaving it to the PreparedStatement to guess the corresponding SQL type)
* @return 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
* @throws DataAccessException if the query fails
* @see #queryForInt(String)
*/
int queryForInt(String sql, 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.
* <p>The results will be mapped to a List (one entry for each row) of
* result objects, each of them matching the specified element type.
* @param sql SQL query to execute
* @param args arguments to bind to the query
* (leaving it to the PreparedStatement to guess the corresponding SQL type)
* @param argTypes SQL types of the arguments
* (constants from <code>java.sql.Types</code>)
* @param elementType the required type of element in the result list
* (for example, <code>Integer.class</code>)
* @return a List of objects that match the specified element type
* @throws DataAccessException if the query fails
* @see #queryForList(String, Class)
* @see SingleColumnRowMapper
*/
List queryForList(String sql, Object[] args, int[] argTypes, Class 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.
* <p>The results will be mapped to a List (one entry for each row) of
* result objects, each of them matching the specified element type.
* @param sql SQL query to execute
* @param args arguments to bind to the query
* (leaving it to the PreparedStatement to guess the corresponding SQL type)
* @param elementType the required type of element in the result list
* (for example, <code>Integer.class</code>)
* @return a List of objects that match the specified element type
* @throws DataAccessException if the query fails
* @see #queryForList(String, Class)
* @see SingleColumnRowMapper
*/
List queryForList(String sql, Object[] args, Class 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.
* <p>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.
* @param sql SQL query to execute
* @param args arguments to bind to the query
* (leaving it to the PreparedStatement to guess the corresponding SQL type)
* @param argTypes SQL types of the arguments
* (constants from <code>java.sql.Types</code>)
* @return a List that contains a Map per row
* @throws DataAccessException if the query fails
* @see #queryForList(String)
* @see java.sql.Types
*/
List queryForList(String sql, 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.
* <p>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.
* @param sql SQL query to execute
* @param args arguments to bind to the query
* (leaving it to the PreparedStatement to guess the corresponding SQL type)
* @return a List that contains a Map per row
* @throws DataAccessException if the query fails
* @see #queryForList(String)
*/
List queryForList(String sql, 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.
* <p>The results will be mapped to an SqlRowSet which holds the data in a
* disconnected fashion. This wrapper will translate any SQLExceptions thrown.
* <p>Note that that, for the default implementation, JDBC RowSet support needs to
* be available at runtime: by default, Sun's <code>com.sun.rowset.CachedRowSetImpl</code>
* 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).
* @param sql SQL query to execute
* @param args arguments to bind to the query
* @param argTypes SQL types of the arguments
* (constants from <code>java.sql.Types</code>)
* @return a SqlRowSet representation (possibly a wrapper around a
* <code>javax.sql.rowset.CachedRowSet</code>)
* @throws DataAccessException if there is any problem executing the query
* @see #queryForRowSet(String)
* @see SqlRowSetResultSetExtractor
* @see javax.sql.rowset.CachedRowSet
* @see java.sql.Types
*/
SqlRowSet queryForRowSet(String sql, 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.
* <p>The results will be mapped to an SqlRowSet which holds the data in a
* disconnected fashion. This wrapper will translate any SQLExceptions thrown.
* <p>Note that that, for the default implementation, JDBC RowSet support needs to
* be available at runtime: by default, Sun's <code>com.sun.rowset.CachedRowSetImpl</code>
* 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).
* @param sql SQL query to execute
* @param args arguments to bind to the query
* (leaving it to the PreparedStatement to guess the corresponding SQL type)
* @return a SqlRowSet representation (possibly a wrapper around a
* <code>javax.sql.rowset.CachedRowSet</code>)
* @throws DataAccessException if there is any problem executing the query
* @see #queryForRowSet(String)
* @see SqlRowSetResultSetExtractor
* @see javax.sql.rowset.CachedRowSet
*/
SqlRowSet queryForRowSet(String sql, Object[] args) throws DataAccessException;
/**
* Issue an update using a PreparedStatementCreator to provide SQL and any
* required parameters.
* @param psc object that provides SQL and any necessary parameters
* @return the number of rows affected
* @throws DataAccessException if there is any problem issuing the update
*/
int update(PreparedStatementCreator psc) throws DataAccessException;
/**
* Issue an update using a PreparedStatementCreator to provide SQL and any
* required parameters. Generetaed keys will to be returned by the List parameter.
* @param psc object that provides SQL and any necessary parameters
* @param generatedKeyHolder KeyHolder that will hold the generated keys
* @return the number of rows affected
* @throws DataAccessException if there is any problem issuing the update
*/
int update(PreparedStatementCreator psc, KeyHolder generatedKeyHolder) 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.
* @param sql SQL, containing bind parameters
* @param pss helper that sets bind parameters. If this is null
* we run an update with static SQL.
* @return the number of rows affected
* @throws DataAccessException if there is any problem issuing the update
*/
int update(String sql, PreparedStatementSetter pss) throws DataAccessException;
/**
* Issue an update via a prepared statement, binding the given arguments.
* @param sql SQL, containing bind parameters
* @param args arguments to bind to the query
* @param argTypes SQL types of the arguments
* (constants from <code>java.sql.Types</code>)
* @return the number of rows affected
* @throws DataAccessException if there is any problem issuing the update
* @see java.sql.Types
*/
int update(String sql, Object[] args, int[] argTypes) throws DataAccessException;
/**
* Issue an update via a prepared statement, binding the given arguments.
* @param sql SQL, containing bind parameters
* @param args arguments to bind to the query
* (leaving it to the PreparedStatement to guess the corresponding SQL type)
* @return the number of rows affected
* @throws DataAccessException if there is any problem issuing the update
*/
int update(String sql, Object[] args) throws DataAccessException;
/**
* Issue multiple updates on a single PreparedStatement, using JDBC 2.0
* batch updates and a BatchPreparedStatementSetter to set values.
* <p>Will fall back to separate updates on a single PreparedStatement
* if the JDBC driver does not support batch updates.
* @param sql defining PreparedStatement that will be reused.
* All statements in the batch will use the same SQL.
* @param pss object to set parameters on the PreparedStatement
* created by this method
* @return an array of the number of rows affected by each statement
* @throws DataAccessException if there is any problem issuing the update
*/
int[] batchUpdate(String sql, BatchPreparedStatementSetter pss)
throws DataAccessException;
//-------------------------------------------------------------------------
// Methods dealing with callable statements
//-------------------------------------------------------------------------
/**
* 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.
* <p>The callback action can return a result object, for example a
* domain object or a collection of domain objects.
* @param csc object that can create a CallableStatement given a Connection
* @param action callback object that specifies the action
* @return a result object returned by the action, or <code>null</code>
* @throws DataAccessException if there is any problem
*/
Object execute(CallableStatementCreator csc, CallableStatementCallback 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.
* <p>The callback action can return a result object, for example a
* domain object or a collection of domain objects.
* @param callString the SQL call string to execute
* @param action callback object that specifies the action
* @return a result object returned by the action, or <code>null</code>
* @throws DataAccessException if there is any problem
*/
Object execute(String callString, CallableStatementCallback action)
throws DataAccessException;
/**
* Execute a SQL call using a CallableStatementCreator to provide SQL and any
* required parameters.
* @param csc object that provides SQL and any necessary parameters
* @param declaredParameters list of declared SqlParameter objects
* @return Map of extracted out parameters
* @throws DataAccessException if there is any problem issuing the update
*/
Map call(CallableStatementCreator csc, List declaredParameters)
throws DataAccessException;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -