From 1cc5c322f3b860b2934120ace8bef2ddbb8a2b44 Mon Sep 17 00:00:00 2001 From: Thomas Gutmann <41593722+speckyspooky@users.noreply.github.com> Date: Sat, 15 Jul 2023 17:03:15 +0200 Subject: [PATCH] Fix prepared statement setNull() #1365 (#1371) * Fix prepared statement setNull() #1365 * Fix missing comment (to restart the build process) --- .../birt/report/data/oda/jdbc/Statement.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/data/org.eclipse.birt.report.data.oda.jdbc/src/org/eclipse/birt/report/data/oda/jdbc/Statement.java b/data/org.eclipse.birt.report.data.oda.jdbc/src/org/eclipse/birt/report/data/oda/jdbc/Statement.java index 0e1aef79de0..9caa2a56e65 100644 --- a/data/org.eclipse.birt.report.data.oda.jdbc/src/org/eclipse/birt/report/data/oda/jdbc/Statement.java +++ b/data/org.eclipse.birt.report.data.oda.jdbc/src/org/eclipse/birt/report/data/oda/jdbc/Statement.java @@ -750,10 +750,20 @@ public void setNull(int parameterId) throws OdaException { try { java.sql.ParameterMetaData pm = this.preStat.getParameterMetaData(); if (pm == null) { - this.preStat.setNull(parameterId, java.sql.Types.OTHER); + try { + this.preStat.setNull(parameterId, java.sql.Types.OTHER); + } catch (SQLException e) { + // fallback, set the null value with SQL default null type + this.preStat.setNull(parameterId, java.sql.Types.NULL); + } addLog("setNull", parameterId, "null"); } else { - this.preStat.setNull(parameterId, pm.getParameterType(parameterId)); + try { + this.preStat.setNull(parameterId, pm.getParameterType(parameterId)); + } catch (SQLException e) { + // fallback, set the null value with SQL default null type + this.preStat.setNull(parameterId, java.sql.Types.NULL); + } } } catch (SQLException e) { throw new JDBCException(ResourceConstants.PREPARESTATEMENT_CANNOT_SET_NULL_VALUE, e); @@ -887,7 +897,7 @@ private void addLog(String methodName, Exception e) { /** * This API is meant to execute the update/DML sql query. * - * @return + * @return Return the execution status * @throws OdaException */ public int executeUpdate() throws OdaException {