Skip to content

Add batch update support to JdbcClient - #36944

Closed
Empatixx wants to merge 1 commit into
spring-projects:mainfrom
Empatixx:feature/jdbcclient-batch-update
Closed

Add batch update support to JdbcClient#36944
Empatixx wants to merge 1 commit into
spring-projects:mainfrom
Empatixx:feature/jdbcclient-batch-update

Conversation

@Empatixx

@Empatixx Empatixx commented Jun 17, 2026

Copy link
Copy Markdown

This adds batch update support to JdbcClient, as requested in gh-33843.

Batch entries are accumulated in a fluent way through a new batch() method on StatementSpec:

int[] rowsAffected = client.sql("INSERT INTO user (first_name, last_name) VALUES (:first, :last)")
        .batch()
            .param("first", "Jane").param("last", "Smith").add()
            .param("first", "John").param("last", "Doe")
        .batchUpdate();

Each entry is bound with param(...) / params(...) / paramSource(...) exactly like a single update; add() separates entries and batchUpdate() executes them as one JDBC batch (the last entry is completed implicitly). Both positional and named parameters are supported (mixing the two in one batch is rejected). It delegates to JdbcOperations.batchUpdate / NamedParameterJdbcOperations.batchUpdate.

Reference docs and integration tests are included. The spring-jdbc build, Checkstyle and tests pass.

I know this is assigned to @sdeleuze — feel free to take whatever is useful here.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 17, 2026
@quaff

quaff commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

I'm expecting more fluent batch API like:

client.sql("insert into person(name, age) values (:name, :age)").batch().param("name", name1).param("age", age1).add().param("name", name2).param("age", age2).batchUpdate();

@Empatixx
Empatixx force-pushed the feature/jdbcclient-batch-update branch from 7f77ae2 to a3b4a5b Compare June 21, 2026 06:30
@Empatixx

Copy link
Copy Markdown
Author

Updated the PR. Batch support is now a single fluent batch() API on StatementSpec: bind each entry with param(...) like a normal update, separate entries with add(), and run them with batchUpdate() (the final entry is flushed automatically). Works for both positional and named parameters. Reference docs and tests updated; the spring-jdbc build, Checkstyle and tests are green.

@Empatixx
Empatixx force-pushed the feature/jdbcclient-batch-update branch 2 times, most recently from 1a8c792 to 6864976 Compare June 21, 2026 06:44
Introduce a fluent batch() operation on JdbcClient.StatementSpec that
accumulates several sets of parameters - bound as positional or named
parameters in the same fashion as a single update, separated by add() -
and executes them as a single JDBC batch through batchUpdate(). Batch
updates previously required dropping down to JdbcTemplate or
NamedParameterJdbcTemplate.

Closes gh-33843

Signed-off-by: Jiří Krokviak <j.krokviak@gmail.com>
@Empatixx
Empatixx force-pushed the feature/jdbcclient-batch-update branch from 6864976 to 808aff8 Compare June 21, 2026 06:49
@quaff

quaff commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

@Empatixx I added batch update with generated keys base on your commit, see https://github.com/quaff/spring-framework/tree/jdbcclient-batch-update

@Empatixx Empatixx closed this by deleting the head repository Aug 29, 2026
@sbrannen

Copy link
Copy Markdown
Member

@Empatixx I added batch update with generated keys base on your commit, see quaff/spring-framework@jdbcclient-batch-update

@quaff, did you intend to submit a PR for that, or did I overlook an existing one?

@sbrannen sbrannen added in: data Issues in data modules (jdbc, orm, oxm, tx) status: invalid An issue that we don't feel is valid type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 29, 2026
quaff added a commit to quaff/spring-framework that referenced this pull request Aug 31, 2026
See spring-projectsGH-36944

Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
@quaff

quaff commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

@quaff, did you intend to submit a PR for that, or did I overlook an existing one?

@sbrannen, I created #37216 base on this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: data Issues in data modules (jdbc, orm, oxm, tx) status: invalid An issue that we don't feel is valid type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants