From 5ebcc5c0531e3eeee95ce809ef9602c5a2e0974e Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Thu, 23 Feb 2023 17:14:29 +0100 Subject: [PATCH] [jOOQ/jOOQ#14696] Wrapping SQLException must copy SQLState and other info from wrapped SQLException --- jOOQ/src/main/java/org/jooq/impl/DefaultBindContext.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultBindContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultBindContext.java index 0ca26c6855..e484d44c56 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultBindContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultBindContext.java @@ -64,8 +64,13 @@ final class DefaultBindContext extends AbstractBindContext { new DefaultBindingSetStatementContext<>(new SimpleExecuteContext(configuration(), data()), stmt, nextIndex, value) ); } + + // [#14696] Maintain SQLState and ErrorCode if the exception is from the driver + catch (SQLException e) { + throw new SQLException("Error while writing value at JDBC bind index: " + nextIndex, e.getSQLState(), e.getErrorCode(), e); + } catch (Exception e) { - throw new SQLException("Error while writing value at JDBC bind index: " + nextIndex ,e); + throw new SQLException("Error while writing value at JDBC bind index: " + nextIndex, e); } return this;