Skip to content

Honor zero maxRows in JDBC result processing - #37419

Open
noojung wants to merge 1 commit into
spring-projects:mainfrom
noojung:fix/jdbc-zero-max-rows
Open

noojung wants to merge 1 commit into
spring-projects:mainfrom
noojung:fix/jdbc-zero-max-rows

Conversation

@noojung

@noojung noojung commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Overview

JDBC defines a maxRows value of zero as unlimited, but the client-side row limiting introduced in #34709 treats it as a limit of zero. As a result, queries using JdbcTemplate and JdbcClient can discard all rows returned by the driver when maxRows is set to 0. This appears to be a regression from the behavior in 6.2.x.

Problem

JdbcTemplate correctly passes zero to the driver through Statement#setMaxRows(0). However, the client-side row limiting added in #34709 only bypasses the limit when maxRows is -1.

For zero, the condition rowNum < maxRows is false before the first row is processed, so the affected result-processing paths stop before handling any of the rows returned by the driver.

These checks exist in RowMapperResultSetExtractor and in the RowCallbackHandler and stream adapters within JdbcTemplate.

JdbcClient operations that delegate to these paths are also affected when using withMaxRows(0).

Fix

Apply client-side limits only for positive maxRows values in RowMapperResultSetExtractor and in the RowCallbackHandler and stream adapters within JdbcTemplate.

Preserve the driver-side handling of -1 (not passed on) and 0 (passed on as no limit), and clarify the meaning of zero in the Javadoc.

Tests

Add regression tests for maxRows=0 across RowMapper, RowCallbackHandler, and stream-based result processing. The tests verify that all expected rows are returned. An H2 integration test also verifies that withMaxRows(0) on JdbcClient returns all matching rows.

Related Issues

Reference

JDBC defines a maxRows value of zero as unlimited. The client-side
row limiting introduced in spring-projectsgh-34709 instead treats it as a limit
of zero, discarding all rows when processing results through a
RowMapper, RowCallbackHandler, or Stream.

Apply client-side limits only for positive maxRows values.

See spring-projectsgh-34709

Signed-off-by: Hyunwoo Jung <hyunwoojung@kakao.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 8, 2026
@sbrannen sbrannen added the in: data Issues in data modules (jdbc, orm, oxm, tx) label Oct 8, 2026
@sbrannen
sbrannen requested a review from jhoeller October 8, 2026 08:50

This branch has not been deployed

No deployments
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: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants