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 via the
Spring TestContext Framework, in the spring-test artifact.
NOTE: As of 6.1, there is a unified JDBC access facade available in
the form of org..
JdbcClient provides a fluent API style for common JDBC queries/updates
with flexible use of indexed or named parameters. It delegates to
JdbcOperations/NamedParameterJdbcOperations for actual execution.
JdbcTemplate, org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations
| Modifier and Type | Method and Description |
|---|---|
| public int[] | Returns: an array of the number of rows affected by each statementdefining an array of SQL statements that will be executed. sql)Issue multiple SQL updates on a single JDBC Statement using batching. |
| public int[] | Returns: an array of the number of rows affected by each statement (may also contain special JDBC-defined negative values for affected rows such asjava./java.)defining PreparedStatement that will be reused.
All statements in the batch will use the same SQL. sql, BatchPreparedStatementSetter object to set parameters on the PreparedStatement
created by this method pss)Issue multiple update statements on a single PreparedStatement, using batch updates and a BatchPreparedStatementSetter to set values. |
| public int[] | Returns: an array of the number of rows affected by each statement (may also contain special JDBC-defined negative values for affected rows such asjava./java.)a callback that creates a PreparedStatement given a Connection psc, BatchPreparedStatementSetter object to set parameters on the PreparedStatement
created by this method pss, KeyHolder a KeyHolder that will hold the generated keys generatedKeyHolder)Issue multiple update statements on a single PreparedStatement, using batch updates and a BatchPreparedStatementSetter to set values. |
| public int[] | Returns: an array containing the numbers of rows affected by each update in the batch (may also contain special JDBC-defined negative values for affected rows such asjava./java.)the SQL statement to execute sql, List<Object[]> the List of Object arrays containing the batch of arguments for the query batchArgs)Execute a batch using the supplied SQL statement with the batch of supplied arguments. |
| public int[] | Returns: an array containing the numbers of rows affected by each update in the batch (may also contain special JDBC-defined negative values for affected rows such asjava./java.)the SQL statement to execute. sql, List<Object[]> the List of Object arrays containing the batch of arguments for the query batchArgs, int[] the SQL types of the arguments
(constants from argTypes)java.sql.Types)Execute a batch using the supplied SQL statement with the batch of supplied arguments. |
| public <T> int[][] | Returns: an array containing for each batch another array containing the numbers of rows affected by each update in the batch (may also contain special JDBC-defined negative values for affected rows such asjava./java.)the SQL statement to execute. sql, Collection<T> the List of Object arrays containing the batch of arguments for the query batchArgs, int batch size batchSize, ParameterizedPreparedStatementSetter<T> the ParameterizedPreparedStatementSetter to use pss)Execute multiple batches using the supplied SQL statement with the collect of supplied arguments. |
| public Map | Returns: a Map of extracted out parametersa callback that provides SQL and any necessary parameters csc, List<SqlParameter> list of declared SqlParameter objects declaredParameters)Execute an SQL call using a CallableStatementCreator to provide SQL and any required parameters. |
| public <T> T | Returns: a result object returned by the action, ornull if nonea callback object that specifies the action action)Execute a JDBC data access operation, implemented as callback action working on a JDBC Connection. |
| public <T> T | Returns: a result object returned by the action, ornull if nonea callback that specifies the action action)Execute a JDBC data access operation, implemented as callback action working on a JDBC Statement. |
| public void | |
| public <T> T | Returns: a result object returned by the action, ornull if nonea callback that creates a PreparedStatement given a Connection psc, PreparedStatementCallback<T> a callback that specifies the action action)Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement. |
| public <T> T | Returns: a result object returned by the action, ornull if nonethe SQL to execute sql, PreparedStatementCallback<T> a callback that specifies the action action)Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement. |
| public <T> T | Returns: a result object returned by the action, ornull if nonea callback that creates a CallableStatement given a Connection csc, CallableStatementCallback<T> a callback that specifies the action action)Execute a JDBC data access operation, implemented as callback action working on a JDBC CallableStatement. |
| public <T> T | Returns: a result object returned by the action, ornull if nonethe SQL call string to execute callString, CallableStatementCallback<T> a callback that specifies the action action)Execute a JDBC data access operation, implemented as callback action working on a JDBC CallableStatement. |
| public <T> T | Returns: an arbitrary result object, as returned by the ResultSetExtractorthe SQL query to execute sql, ResultSetExtractor<T> a callback that will extract all rows of results rse)Execute a query given static SQL, reading the ResultSet with a ResultSetExtractor. |
| public void | query(String
the SQL query to execute sql, RowCallbackHandler a callback that will extract results, one row at a time rch)Execute a query given static SQL, reading the ResultSet on a per-row basis with a RowCallbackHandler. |
| public <T> List | |
| public <T> T | Returns: an arbitrary result object, as returned by the ResultSetExtractora callback that creates a PreparedStatement given a Connection psc, ResultSetExtractor<T> a callback that will extract results rse)Query using a prepared statement, reading the ResultSet with a ResultSetExtractor. |
| public <T> T | Returns: an arbitrary result object, as returned by the ResultSetExtractorthe SQL query to execute sql, PreparedStatementSetter a callback that knows how to set values on the prepared statement.
If this is pss, ResultSetExtractor<T> null, the SQL will be assumed to contain no bind parameters.
Even if there are no bind parameters, this callback may be used to set the
fetch size and other performance options.a callback that will extract results rse)Query using a prepared statement, reading the ResultSet with a ResultSetExtractor. |
| public <T> T | Returns: an arbitrary result object, as returned by the ResultSetExtractorthe SQL query to execute sql, Object[] arguments to bind to the query args, int[] the SQL types of the arguments
(constants from argTypes, ResultSetExtractor<T> java.sql.Types)a callback that will extract results 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. |
| public <T> T | Returns: an arbitrary result object, as returned by the ResultSetExtractorthe SQL query to execute sql, Object[] arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain args, ResultSetExtractor<T> SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scalea callback that will extract results rse)
Deprecated
as of 5.3, in favor of
query(String, ResultSetExtractor, Object.
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. |
| public <T> T | Returns: an arbitrary result object, as returned by the ResultSetExtractorthe SQL query to execute sql, ResultSetExtractor<T> a callback that will extract results rse, Object... arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain args)SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scaleQuery 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. |
| public void | query(PreparedStatementCreator
a callback that creates a PreparedStatement given a Connection psc, RowCallbackHandler a callback that will extract results, one row at a time rch)Query using a prepared statement, reading the ResultSet on a per-row basis with a RowCallbackHandler. |
| public void | query(String
the SQL query to execute sql, PreparedStatementSetter a callback that knows how to set values on the prepared statement.
If this is pss, RowCallbackHandler null, the SQL will be assumed to contain no bind parameters.
Even if there are no bind parameters, this callback may be used to set the
fetch size and other performance options.a callback that will extract results, one row at a time 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. |
| public void | query(String
the SQL query to execute sql, Object[] arguments to bind to the query args, int[] the SQL types of the arguments
(constants from argTypes, RowCallbackHandler java.sql.Types)a callback that will extract results, one row at a time 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. |
| public void | query(String
the SQL query to execute sql, Object[] arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain args, RowCallbackHandler SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scalea callback that will extract results, one row at a time rch)
Deprecated
as of 5.3, in favor of
query(String, RowCallbackHandler, Object.
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. |
| public void | query(String
the SQL query to execute sql, RowCallbackHandler a callback that will extract results, one row at a time rch, Object... arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain args)SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scaleQuery 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. |
| public <T> List | Returns: the result List, containing mapped objectsa callback that creates a PreparedStatement given a Connection psc, RowMapper<T> a callback that will map one object per row rowMapper)Query using a prepared statement, mapping each row to a result object via a RowMapper. |
| public <T> List | Returns: the result List, containing mapped objectsthe SQL query to execute sql, PreparedStatementSetter a callback that knows how to set values on the prepared statement.
If this is pss, RowMapper<T> null, the SQL will be assumed to contain no bind parameters.
Even if there are no bind parameters, this callback may be used to set the
fetch size and other performance options.a callback that will map one object per row 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 result object via a RowMapper. |
| public <T> List | Returns: the result List, containing mapped objectsthe SQL query to execute sql, Object[] arguments to bind to the query args, int[] the SQL types of the arguments
(constants from argTypes, RowMapper<T> java.sql.Types)a callback that will map one object per row 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 result object via a RowMapper. |
| public <T> List | Returns: the result List, containing mapped objectsthe SQL query to execute sql, Object[] arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain args, RowMapper<T> SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scalea callback that will map one object per row rowMapper)
Deprecated
as of 5.3, in favor of
query(String, RowMapper, Object.
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 result object via a RowMapper. |
| public <T> List | Returns: the result List, containing mapped objectsthe SQL query to execute sql, RowMapper<T> a callback that will map one object per row rowMapper, Object... arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain args)SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scaleQuery given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping each row to a result object via a RowMapper. |
| public <T> List | Returns: a List of objects that match the specified element typethe SQL query to execute sql, Class<T> the required type of element in the result list
(for example, elementType)Integer.class)Execute a query for a result list, given static SQL. |
| public List | Returns: a List that contains a Map per rowthe SQL query to execute sql)Execute a query for a result list, given static SQL. |
| public <T> List | Returns: a List of objects that match the specified element typethe SQL query to execute sql, Object[] arguments to bind to the query args, int[] the SQL types of the arguments
(constants from argTypes, Class<T> java.sql.Types)the required type of element in the result list
(for example, elementType)Integer.class)Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list. |
| public <T> List | Returns: a List of objects that match the specified element typethe SQL query to execute sql, Object[] arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain args, Class<T> SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scalethe required type of element in the result list
(for example, elementType)Integer.class)
Deprecated
as of 5.3, in favor of
queryForList(String, Class, Object.
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list. |
| public <T> List | Returns: a List of objects that match the specified element typethe SQL query to execute sql, Class<T> the required type of element in the result list
(for example, elementType, Object... Integer.class)arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain args)SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scaleQuery given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list. |
| public List | Returns: a List that contains a Map per rowthe SQL query to execute sql, Object[] arguments to bind to the query args, int[] the SQL types of the arguments
(constants from argTypes)java.sql.Types)Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list. |
| public List | Returns: a List that contains a Map per rowthe SQL query to execute sql, Object... arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain args)SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scaleQuery given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list. |
| public Map | Returns: the result Map (one entry per column, with column name as key)the SQL query to execute sql)Execute a query for a result map, given static SQL. |
| public Map | Returns: the result Map (one entry per column, with column name as key)the SQL query to execute sql, Object[] arguments to bind to the query args, int[] the SQL types of the arguments
(constants from argTypes)java.sql.Types)Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result map. |
| public Map | Returns: the result Map (one entry for each column, using the column name as the key)the SQL query to execute sql, Object... arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain args)SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scaleQuery given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result map. |
| public <T> T | queryForObject(String
the SQL query to execute sql, RowMapper<T> a callback that will map one object per row rowMapper)Execute a query given static SQL, mapping a single result row to a result object via a RowMapper. |
| public <T> T | Returns: the result object of the required type, ornull in case of SQL NULLthe SQL query to execute sql, Class<T> the type that the result object is expected to match requiredType)Execute a query for a result object, given static SQL. |
| public <T> T | queryForObject(String
the SQL query to execute sql, Object[] arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type) args, int[] the SQL types of the arguments
(constants from argTypes, RowMapper<T> java.sql.Types)a callback that will map one object per row 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 result object via a RowMapper. |
| public <T> T | queryForObject(String
the SQL query to execute sql, Object[] arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain args, RowMapper<T> SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scalea callback that will map one object per row rowMapper)
Deprecated
as of 5.3, in favor of
queryForObject(String, RowMapper, Object.
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 result object via a RowMapper. |
| public <T> T | queryForObject(String
the SQL query to execute sql, RowMapper<T> a callback that will map one object per row rowMapper, Object... arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain args)SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scaleQuery 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 result object via a RowMapper. |
| public <T> T | Returns: the result object of the required type, ornull in case of SQL NULLthe SQL query to execute sql, Object[] arguments to bind to the query args, int[] the SQL types of the arguments
(constants from argTypes, Class<T> java.sql.Types)the type that the result object is expected to match 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. |
| public <T> T | Returns: the result object of the required type, ornull in case of SQL NULLthe SQL query to execute sql, Object[] arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain args, Class<T> SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scalethe type that the result object is expected to match requiredType)
Deprecated
as of 5.3, in favor of
queryForObject(String, Class, Object.
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result object. |
| public <T> T | Returns: the result object of the required type, ornull in case of SQL NULLthe SQL query to execute sql, Class<T> the type that the result object is expected to match requiredType, Object... arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain args)SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scaleQuery given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result object. |
| public SqlRowSet | Returns: an SqlRowSet representation (possibly a wrapper around ajavax.sql.rowset.CachedRowSet)the SQL query to execute sql)Execute a query for an SqlRowSet, given static SQL. |
| public SqlRowSet | Returns: an SqlRowSet representation (possibly a wrapper around ajavax.sql.rowset.CachedRowSet)the SQL query to execute sql, Object[] arguments to bind to the query args, int[] the SQL types of the arguments
(constants from argTypes)java.sql.Types)Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting an SqlRowSet. |
| public SqlRowSet | Returns: an SqlRowSet representation (possibly a wrapper around ajavax.sql.rowset.CachedRowSet)the SQL query to execute sql, Object... arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain args)SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scaleQuery given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting an SqlRowSet. |
| public <T> Stream | Returns: the result Stream, containing mapped objects, needing to be closed once fully processed (e.g. through a try-with-resources clause)the SQL query to execute sql, RowMapper<T> a callback that will map one object per row rowMapper)Execute a query given static SQL, mapping each row to a result object via a RowMapper, and turning it into an iterable and closeable Stream. |
| public <T> Stream | Returns: the result Stream, containing mapped objects, needing to be closed once fully processed (e.g. through a try-with-resources clause)a callback that creates a PreparedStatement given a Connection psc, RowMapper<T> a callback that will map one object per row rowMapper)Query using a prepared statement, mapping each row to a result object via a RowMapper, and turning it into an iterable and closeable Stream. |
| public <T> Stream | Returns: the result Stream, containing mapped objects, needing to be closed once fully processed (e.g. through a try-with-resources clause)the SQL query to execute sql, PreparedStatementSetter a callback that knows how to set values on the prepared statement.
If this is pss, RowMapper<T> null, the SQL will be assumed to contain no bind parameters.
Even if there are no bind parameters, this callback may be used to set the
fetch size and other performance options.a callback that will map one object per row 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 result object via a RowMapper, and turning it into an iterable and closeable Stream. |
| public <T> Stream | Returns: the result Stream, containing mapped objects, needing to be closed once fully processed (e.g. through a try-with-resources clause)the SQL query to execute sql, RowMapper<T> a callback that will map one object per row rowMapper, Object... arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain args)SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scaleQuery given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping each row to a result object via a RowMapper, and turning it into an iterable and closeable Stream. |
| public int | |
| public int | Returns: the number of rows affecteda callback that provides SQL and any necessary parameters 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. |
| public int | Returns: the number of rows affecteda callback that provides SQL and any necessary parameters psc, KeyHolder a KeyHolder that will hold the generated keys generatedKeyHolder)Issue an update statement using a PreparedStatementCreator to provide SQL and any required parameters. |
| public int | Returns: the number of rows affectedthe SQL containing bind parameters sql, PreparedStatementSetter helper that sets bind parameters. If this is pss)null
we run an update with static SQL.Issue an update statement using a PreparedStatementSetter to set bind parameters, with given SQL. |
| public int | Returns: the number of rows affectedthe SQL containing bind parameters sql, Object[] arguments to bind to the query args, int[] the SQL types of the arguments
(constants from argTypes)java.sql.Types)Issue a single SQL update operation (such as an insert, update or delete statement) via a prepared statement, binding the given arguments. |
| public int | Returns: the number of rows affectedthe SQL containing bind parameters sql, Object... arguments to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type);
may also contain args)SqlParameterValue objects which indicate not
only the argument value but also the SQL type and optionally the scaleIssue a single SQL update operation (such as an insert, update or delete statement) via a prepared statement, binding the given arguments. |