Package org.springframework.jdbc.core.simple

# Interface JdbcClient

public interface JdbcClient
A fluent `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`. 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`.

Since:
  6.1
Author:
  Juergen Hoeller, Sam Brannen
See Also:
  - `ResultSetExtractor`
  - `RowCallbackHandler`
  - `RowMapper`
  - `JdbcOperations`
  - `NamedParameterJdbcOperations`
  - `JdbcTemplate`
  - `NamedParameterJdbcTemplate`

## Nested Class Summary

Nested Classes
Modifier and Type
Interface
Description
`static interface`
`JdbcClient.MappedQuerySpec<T>`
A specification for RowMapper-mapped queries.
`static interface`
`JdbcClient.ResultQuerySpec`
A specification for simple result queries.
`static interface`
`JdbcClient.StatementSpec`
A statement specification for parameter bindings and query/update execution.

## Method Summary

Modifier and Type
Method
Description
`static JdbcClient`
`create(DataSource dataSource)`
Create a `JdbcClient` for the given `DataSource`.
`static JdbcClient`
`create(JdbcOperations jdbcTemplate)`
Create a `JdbcClient` for the given `JdbcOperations` delegate, typically an `JdbcTemplate`.
`static JdbcClient`
`create(NamedParameterJdbcOperations jdbcTemplate)`
Create a `JdbcClient` for the given `NamedParameterJdbcOperations` delegate, typically an `NamedParameterJdbcTemplate`.
`JdbcClient.StatementSpec`
`sql(String sql)`
The starting point for any JDBC operation: a custom SQL String.

## Method Details

### sql

JdbcClient.StatementSpec sql(String 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

static JdbcClient create(DataSource dataSource)
Create a `JdbcClient` for the given `DataSource`.

Parameters:
  `dataSource` - the DataSource to obtain connections from

### create

static JdbcClient create(JdbcOperations jdbcTemplate)
Create a `JdbcClient` for the given `JdbcOperations` delegate, typically an `JdbcTemplate`.

Use this factory method to reuse existing `JdbcTemplate` configuration, including its `DataSource`.

Parameters:
  `jdbcTemplate` - the delegate to perform operations on

### create

static JdbcClient create(NamedParameterJdbcOperations jdbcTemplate)
Create a `JdbcClient` for the given `NamedParameterJdbcOperations` delegate, typically an `NamedParameterJdbcTemplate`.

Use this factory method to reuse existing `NamedParameterJdbcTemplate` configuration, including its underlying `JdbcTemplate` and `DataSource`.

Parameters:
  `jdbcTemplate` - the delegate to perform operations on