Interface JdbcClient
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 JdbcTemplate and
NamedParameterJdbcTemplate.
Batch updates are supported in a fluent fashion through JdbcClient.StatementSpec.batch();
for other complex JDBC operations — for example, stored procedure calls —
you may use those lower-level template classes directly, or alternatively
SimpleJdbcInsert and SimpleJdbcCall.
- Since:
- 6.1
- Author:
- Juergen Hoeller, Sam Brannen, Jiri Krokviak, Yanming Zhou
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA specification for accumulating several sets of parameters for a batch update, with each set representing the parameters for one statement execution within the batch.static interfaceJdbcClient.MappedQuerySpec<T extends @Nullable Object>A specification for RowMapper-mapped queries.static interfaceA specification for simple result queries.static interfaceA statement specification for parameter bindings and query/update execution. -
Method Summary
Modifier and TypeMethodDescriptionstatic JdbcClientcreate(DataSource dataSource) Create aJdbcClientfor the givenDataSource.static JdbcClientcreate(JdbcOperations jdbcTemplate) static JdbcClientcreate(NamedParameterJdbcOperations jdbcTemplate) Create aJdbcClientfor the givenNamedParameterJdbcOperationsdelegate, typically anNamedParameterJdbcTemplate.static JdbcClientcreate(NamedParameterJdbcOperations jdbcTemplate, org.springframework.core.convert.ConversionService conversionService) Create aJdbcClientfor the givenNamedParameterJdbcOperationsdelegate, typically anNamedParameterJdbcTemplate.The starting point for any JDBC operation: a custom SQL String.
-
Method Details
-
sql
The starting point for any JDBC operation: a custom SQL String.- Parameters:
sql- the SQL query or update statement as a String- Returns:
- a chained statement specification
-
create
Create aJdbcClientfor the givenDataSource.- Parameters:
dataSource- the DataSource to obtain connections from
-
create
Create aJdbcClientfor the givenJdbcOperationsdelegate, typically anJdbcTemplate.Use this factory method to reuse existing
JdbcTemplateconfiguration, including itsDataSource.- Parameters:
jdbcTemplate- the delegate to perform operations on
-
create
Create aJdbcClientfor the givenNamedParameterJdbcOperationsdelegate, typically anNamedParameterJdbcTemplate.Use this factory method to reuse existing
NamedParameterJdbcTemplateconfiguration, including its underlyingJdbcTemplateandDataSource.- Parameters:
jdbcTemplate- the delegate to perform operations on
-
create
static JdbcClient create(NamedParameterJdbcOperations jdbcTemplate, org.springframework.core.convert.ConversionService conversionService) Create aJdbcClientfor the givenNamedParameterJdbcOperationsdelegate, typically anNamedParameterJdbcTemplate.Use this factory method to reuse existing
NamedParameterJdbcTemplateconfiguration, including its underlyingJdbcTemplateandDataSource, along with a customConversionServicefor queries with mapped classes.- Parameters:
jdbcTemplate- the delegate to perform operations onconversionService- aConversionServicefor converting fetched JDBC values to mapped classes inJdbcClient.StatementSpec.query(Class)- Since:
- 7.0
-