JdbcClient with common JDBC query and update operations,
supporting JDBC-style positional as well as Spring-style named parameters
with a convenient unified facade for JDBC PreparedStatement execution.
An example for retrieving a query result as a java.util.Optional:
Optional<Integer> value = client.sql("SELECT AGE FROM CUSTOMER WHERE ID = :id")
.param("id", 3)
.query(Integer.class)
.optional();
Delegates to org. and
org..
For complex JDBC operations — for example, batch inserts and stored
procedure calls — you may use those lower-level template classes directly,
or alternatively SimpleJdbcInsert and SimpleJdbcCall.
ResultSetExtractor, RowCallbackHandler, RowMapper, JdbcOperations, NamedParameterJdbcOperations, org.springframework.jdbc.core.JdbcTemplate , org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
| Modifier and Type | Class and Description |
|---|---|
| public static interface | JdbcClient.
the RowMapper-declared result type T>A specification for RowMapper-mapped queries. |
| public static interface | JdbcClient.
A specification for simple result queries. |
| public static interface | JdbcClient.
A statement specification for parameter bindings and query/update execution. |
| Modifier and Type | Method and Description |
|---|---|
| public static JdbcClient | create(DataSource
the DataSource to obtain connections from dataSource)Create a |
| public static JdbcClient | create(JdbcOperations
the delegate to perform operations on jdbcTemplate)Create a |
| public static JdbcClient | create(NamedParameterJdbcOperations
the delegate to perform operations on jdbcTemplate)Create a |
| public JdbcClient. |
| create | back to summary |
|---|---|
| public static JdbcClient create(DataSource dataSource) Create a
| |
| create | back to summary |
|---|---|
| public static JdbcClient create(JdbcOperations jdbcTemplate) Create a Use this factory method to reuse existing
| |
| create | back to summary |
|---|---|
| public static JdbcClient create(NamedParameterJdbcOperations jdbcTemplate) Create a Use this factory method to reuse existing
| |
| sql | back to summary |
|---|---|
| public JdbcClient. The starting point for any JDBC operation: a custom SQL String.
| |
| Modifier and Type | Method and Description |
|---|---|
| public List | Returns: the result as a detached List, containing mapped objectsRetrieve the result as a pre-resolved list of mapped objects, retaining the order from the original database result. |
| public default Optional | |
| public default Set | Returns: the result as a detached Set, containing mapped objectsRetrieve the result as an order-preserving set of mapped objects. |
| public default T | Returns: the single result object (nevernull)Retrieve a single result as a required object instance. |
| public Stream | Returns: the result Stream, containing mapped objects, needing to be closed once fully processed (e.g. through a try-with-resources clause)Retrieve the result as a lazily resolved stream of mapped objects, retaining the order from the original database result. |
| list | back to summary |
|---|---|
| public List Retrieve the result as a pre-resolved list of mapped objects, retaining the order from the original database result.
| |
| optional | back to summary |
|---|---|
| public default Optional Retrieve a single result, if available, as an
| |
| set | back to summary |
|---|---|
| public default Set Retrieve the result as an order-preserving set of mapped objects.
| |
| single | back to summary |
|---|---|
| public default T single() Retrieve a single result as a required object instance.
| |
| stream | back to summary |
|---|---|
| public Stream Retrieve the result as a lazily resolved stream of mapped objects, retaining the order from the original database result.
| |
| Modifier and Type | Method and Description |
|---|---|
| public List | Returns: a (potentially empty) list of rows, with each result row represented as a map of case-insensitive column names to column valuesRetrieve the result as a list of rows, retaining the order from the original database result. |
| public SqlRowSet | Returns: a detached row set representation of the original database resultRetrieve the result as a row set. |
| public List | Returns: a (potentially empty) list of rows, with each row represented as its single column valueRetrieve a single column result, retaining the order from the original database result. |
| public Map | Returns: the result row represented as a map of case-insensitive column names to column valuesRetrieve a single row result. |
| public default Object | Returns: the single row represented as its single column valueRetrieve a single value result. |
| listOfRows | back to summary |
|---|---|
| public List Retrieve the result as a list of rows, retaining the order from the original database result. | |
| rowSet | back to summary |
|---|---|
| public SqlRowSet rowSet() Retrieve the result as a row set.
| |
| singleColumn | back to summary |
|---|---|
| public List Retrieve a single column result, retaining the order from the original database result. | |
| singleRow | back to summary |
|---|---|
| public Map Retrieve a single row result. | |
| singleValue | back to summary |
|---|---|
| public default Object singleValue() Retrieve a single value result.
| |
| Modifier and Type | Method and Description |
|---|---|
| public JdbcClient. | |
| public JdbcClient. | |
| public JdbcClient. | Returns: this statement specification (for chaining)the JDBC-style index (starting with 1) jdbcIndex, Object the parameter value to bind value, int the associated SQL type (see sqlType)java.)Bind a positional JDBC statement parameter for "?" placeholder resolution by explicit JDBC statement parameter index. |
| public JdbcClient. | |
| public JdbcClient. | Returns: this statement specification (for chaining)the parameter name name, Object the parameter value to bind value, int the associated SQL type (see sqlType)java.)Bind a named statement parameter for ":x" placeholder resolution, with each "x" name matching a ":x" placeholder in the SQL statement. |
| public JdbcClient. | |
| public JdbcClient. | |
| public JdbcClient. | |
| public JdbcClient. | Returns: this statement specification (for chaining)a custom parameter object (e.g. a JavaBean,
record class, or field holder) with named properties serving as
statement parameters namedParamObject)Bind named statement parameters for ":x" placeholder resolution. |
| public JdbcClient. | Returns: this statement specification (for chaining)a custom namedParamSource)SqlParameterSource instanceBind named statement parameters for ":x" placeholder resolution. |
| public JdbcClient. | Returns: the result query specificationProceed towards execution of a query, with several result options available in the returned query specification. |
| public <T> JdbcClient. | Returns: the mapped query specificationthe target class to apply a RowMapper for
(either a simple value type for a single column mapping or a
JavaBean / record class / field holder for a multi-column mapping) mappedClass)Proceed towards execution of a mapped query, with several options available in the returned query specification. |
| public <T> JdbcClient. | |
| public void | query(RowCallbackHandler
a callback for processing each row in the ResultSet rch)Execute a query with the provided SQL statement, processing each row with the given callback. |
| public <T> T | Returns: the value returned by the ResultSetExtractora callback for processing the entire ResultSet rse)Execute a query with the provided SQL statement, returning a result object for the entire ResultSet. |
| public int | |
| public int | Returns: the number of rows affecteda KeyHolder that will hold the generated keys
(typically a generatedKeyHolder)org.)Execute the provided SQL statement as an update. |
| public int | Returns: the number of rows affecteda KeyHolder that will hold the generated keys
(typically a generatedKeyHolder, String... org.)names of the columns that will have keys generated for them keyColumnNames)Execute the provided SQL statement as an update. |
| param | back to summary |
|---|---|
| public JdbcClient. Bind a positional JDBC statement parameter for "?" placeholder resolution by implicit order of parameter value registration. This is primarily intended for statements with a single parameter or very few parameters, registering each parameter value in the order of the parameter's occurrence in the SQL statement.
| |
| param | back to summary |
|---|---|
| public JdbcClient. Bind a positional JDBC statement parameter for "?" placeholder resolution by explicit JDBC statement parameter index.
| |
| param | back to summary |
|---|---|
| public JdbcClient. Bind a positional JDBC statement parameter for "?" placeholder resolution by explicit JDBC statement parameter index.
| |
| param | back to summary |
|---|---|
| public JdbcClient. Bind a named statement parameter for ":x" placeholder resolution, with each "x" name matching a ":x" placeholder in the SQL statement.
| |
| param | back to summary |
|---|---|
| public JdbcClient. Bind a named statement parameter for ":x" placeholder resolution, with each "x" name matching a ":x" placeholder in the SQL statement.
| |
| params | back to summary |
|---|---|
| public JdbcClient. Bind a var-args list of positional parameters for "?" placeholder resolution. The given list will be added to existing positional parameters, if any. Each element from the complete list will be bound as a JDBC positional parameter with a corresponding JDBC index (i.e. list index + 1).
| |
| params | back to summary |
|---|---|
| public JdbcClient. Bind a list of positional parameters for "?" placeholder resolution. The given list will be added to existing positional parameters, if any. Each element from the complete list will be bound as a JDBC positional parameter with a corresponding JDBC index (i.e. list index + 1).
| |
| params | back to summary |
|---|---|
| public JdbcClient. Bind named statement parameters for ":x" placeholder resolution. The given map will be merged into existing named parameters, if any.
| |
| paramSource | back to summary |
|---|---|
| public JdbcClient. Bind named statement parameters for ":x" placeholder resolution. The given parameter object will define all named parameters based on its JavaBean properties, record components, or raw fields. A Map instance can be provided as a complete parameter source as well.
| |
| paramSource | back to summary |
|---|---|
| public JdbcClient. Bind named statement parameters for ":x" placeholder resolution. The given parameter source will define all named parameters, possibly associating specific SQL types with each value.
| |
| query | back to summary |
|---|---|
| public JdbcClient. Proceed towards execution of a query, with several result options available in the returned query specification.
| |
| query | back to summary |
|---|---|
| public <T> JdbcClient. Proceed towards execution of a mapped query, with several options available in the returned query specification.
| |
| query | back to summary |
|---|---|
| public <T> JdbcClient. Proceed towards execution of a mapped query, with several options available in the returned query specification.
| |
| query | back to summary |
|---|---|
| public void query(RowCallbackHandler rch) Execute a query with the provided SQL statement, processing each row with the given callback.
| |
| query | back to summary |
|---|---|
| public <T> T query(ResultSetExtractor<T> rse) Execute a query with the provided SQL statement, returning a result object for the entire ResultSet.
| |
| update | back to summary |
|---|---|
| public int update() Execute the provided SQL statement as an update.
| |
| update | back to summary |
|---|---|
| public int update(KeyHolder generatedKeyHolder) Execute the provided SQL statement as an update. This method requires support for generated keys in the JDBC driver.
| |
| update | back to summary |
|---|---|
| public int update(KeyHolder generatedKeyHolder, String... keyColumnNames) Execute the provided SQL statement as an update. This method requires support for generated keys in the JDBC driver.
| |