Parameters, row mapping, single/optional/list, generated keys, batch via NamedParameterJdbcTemplate (JdbcClient has none), exception translation, transactions, an unclosed stream() exhausting a 2-connection pool, withMaxRows truncating silently, and spring.jdbc.template.* reaching the auto-configured JdbcClient. JdbcClient API diffed across 6.1.0, 6.2.19 and 7.0.0. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b5n3PRbPkUsiJybTeg
3.5 KiB
jdbcclient
Companion code for JdbcClient in Spring Framework 7: Modern JDBC Without JPA (vs JdbcTemplate) on ankurm.com.
One product table on in-memory H2, a JdbcClient repository next to the same four operations written with
JdbcTemplate, and twelve transcripts that record what the API really does, including the failures.
Versions
| Component | Version |
|---|---|
| Spring Boot | 4.1.2 |
Spring Framework (spring-jdbc) |
7.0.10 (7.0.0 reached Maven Central on 13 Nov 2025) |
| HikariCP | 7.0.2 |
| H2 | 2.4.240 |
| JDK | 25 (Temurin 25.0.5) |
Run it
./scripts/run-all.sh # runs the tests, which regenerate everything in output/
No Docker and no database to install. Exception messages and a few behaviours (generated-key columns, the wording of constraint errors) are H2's; the shape of what Spring does is the same on other databases.
Source
| File | What it shows |
|---|---|
ProductRepository.java |
the JdbcClient version: named parameters, paramSource(record), optional(), generated keys, stream() |
ProductRepositoryJdbcTemplate.java |
the same operations with JdbcTemplate and NamedParameterJdbcTemplate |
StockService.java |
two UPDATEs with and without @Transactional |
Product.java |
the record the rows map to |
Captured output
| File | Shows |
|---|---|
01-same-results.txt |
both repositories return identical rows |
02-api-surface.txt |
every method on JdbcClient and its spec interfaces, by reflection; there is no batch method |
03-parameters.txt |
nine ways to pass parameters and four ways to get them wrong |
04-mapping.txt |
records, beans, lambdas, missing columns, wrong types, SQL NULL into a primitive |
05-result-shapes.txt |
list, single, optional, set on 0, 1 and 4 rows |
06-generated-keys.txt |
KeyHolder with and without column names |
07-batch.txt |
batching through NamedParameterJdbcTemplate |
08-exceptions.txt |
what constraint violations and bad SQL turn into |
09-transactions.txt |
the same body with and without a transaction |
10-stream-leak.txt |
unclosed stream() calls exhausting a two-connection pool |
11-limits.txt |
withMaxRows truncating silently, withQueryTimeout |
12-template-properties.txt |
spring.jdbc.template.max-rows reaching the auto-configured JdbcClient |
| 13-api-diff.txt | JdbcClient signatures diffed across 6.1.0, 6.2.0, 6.2.19, 7.0.0 and 7.0.10 (scripts/api-diff.sh) |
| 14-default-jdbcclient.txt | the fields and constructors of DefaultJdbcClient in 7.0.10 (scripts/api-diff.sh) |
13 and 14 come from ./scripts/api-diff.sh, which downloads the spring-jdbc jars from Maven Central and needs network access.
Timings and the speed comparison in 07 are indicative: they vary between runs and H2 has no network round trip.