Skip to content

Report batch failures with BatchUpdateException and update counts - #903

Merged
staticlibs merged 1 commit into
duckdb:mainfrom
hutiefang76:frank/nextten-duckdb-java-scout-20261009-01a11186
Oct 9, 2026
Merged

staticlibs merged 1 commit into
duckdb:mainfrom
hutiefang76:frank/nextten-duckdb-java-scout-20261009-01a11186

Conversation

@hutiefang76

Copy link
Copy Markdown
Contributor

When a command in a batch fails, both Statement and PreparedStatement currently rethrow a plain SQLException. Callers that catch BatchUpdateException cannot inspect which commands executed before the failure.

Wrap the error in BatchUpdateException with the executed prefix of update counts and preserve its SQLState, vendor code and cause. Use the long[] constructor for both executeBatch and executeLargeBatch, keeping the existing stop-at-first-failure and transaction behavior.

The regression tests fail against the original implementation. After the change, TestBatch (17 tests) and TestPrepare (28 tests) pass with the locally built native driver on macOS arm64/JDK 17:

GEN=ninja make release
java -cp build/release/duckdb_jdbc.jar:build/release/duckdb_jdbc_tests.jar org.duckdb.TestDuckDBJDBC TestBatch
java -cp build/release/duckdb_jdbc.jar:build/release/duckdb_jdbc_tests.jar org.duckdb.TestDuckDBJDBC TestPrepare

make test reaches an unrelated failure in test_scalar_function_vectorized_parallel_streams (a result unexpectedly becomes NULL). That test also fails in three isolated runs with the original PreparedStatement implementation. I am investigating that separately; this PR does not claim the full suite passes. The modified Java files pass clang-format.

AI assistance was used for implementation and review.

Signed-off-by: hutiefang76 <137664623+hutiefang76@users.noreply.github.com>

@staticlibs staticlibs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Looks good to me.

@staticlibs
staticlibs merged commit 11b9357 into duckdb:main Oct 9, 2026
31 of 32 checks passed
staticlibs pushed a commit that referenced this pull request Oct 10, 2026
This is a backport of the PR #903 to `v2.0-cyanoptera` branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants