From c9235a02b4857c614a24082938d3f2eba1c388ee Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Mon, 15 Jan 2024 04:41:29 +0100 Subject: [PATCH] IDEMPIERE-5994 Connection leak when using DB.prepareStatement(badSql, null) (#2184) * IDEMPIERE-5994 Connection leak when using DB.prepareStatement(badSql, null) * - implement approach suggested by Heng Sin --- .../src/org/compiere/db/PreparedStatementProxy.java | 6 ++++++ org.adempiere.base/src/org/compiere/db/StatementProxy.java | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/org.adempiere.base/src/org/compiere/db/PreparedStatementProxy.java b/org.adempiere.base/src/org/compiere/db/PreparedStatementProxy.java index dcfedcad66..b6b4c44d29 100644 --- a/org.adempiere.base/src/org/compiere/db/PreparedStatementProxy.java +++ b/org.adempiere.base/src/org/compiere/db/PreparedStatementProxy.java @@ -15,6 +15,7 @@ package org.compiere.db; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.sql.SQLException; import java.util.logging.Level; import javax.sql.RowSet; @@ -95,6 +96,11 @@ public class PreparedStatementProxy extends StatementProxy { p_stmt = conn.prepareStatement(p_vo.getSql(), p_vo .getResultSetType(), p_vo.getResultSetConcurrency()); } catch (Exception e) { + try { + this.close(); + } catch (SQLException e1) { + // ignore + } log.log(Level.SEVERE, p_vo.getSql(), e); throw new DBException(e); } diff --git a/org.adempiere.base/src/org/compiere/db/StatementProxy.java b/org.adempiere.base/src/org/compiere/db/StatementProxy.java index ff59984f32..9fd61a7d8e 100644 --- a/org.adempiere.base/src/org/compiere/db/StatementProxy.java +++ b/org.adempiere.base/src/org/compiere/db/StatementProxy.java @@ -184,7 +184,7 @@ public class StatementProxy implements InvocationHandler { * @throws SQLException * @see java.sql.Statement#close() */ - private void close () throws SQLException + protected void close () throws SQLException { if (close) return;