From b46a2dd4ed3e503ca2285f034de3b3b7a5a94fcb Mon Sep 17 00:00:00 2001 From: "Redhuan D. Oon" Date: Fri, 8 Feb 2008 19:13:13 +0000 Subject: [PATCH] *BF [ 1874419 ] JDBC Statement not close in a finally block *Organize imports --- base/src/org/compiere/model/MAlert.java | 31 +++++++++++-------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/base/src/org/compiere/model/MAlert.java b/base/src/org/compiere/model/MAlert.java index 47d0237373..50b1f8cabf 100644 --- a/base/src/org/compiere/model/MAlert.java +++ b/base/src/org/compiere/model/MAlert.java @@ -16,10 +16,13 @@ *****************************************************************************/ package org.compiere.model; -import java.sql.*; -import java.util.*; -import java.util.logging.*; -import org.compiere.util.*; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.ArrayList; +import java.util.Properties; +import java.util.logging.Level; + +import org.compiere.util.DB; /** * Alert Model @@ -80,31 +83,25 @@ public class MAlert extends X_AD_Alert + "WHERE AD_Alert_ID=?"; ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, getAD_Alert_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MAlertRule (getCtx(), rs, null)); - rs.close (); - pstmt.close (); - pstmt = null; - } + } catch (Exception e) { log.log(Level.SEVERE, sql, e); } - try + finally { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; + DB.close(rs, pstmt); + rs = null; pstmt = null; } + // m_rules = new MAlertRule[list.size ()]; list.toArray (m_rules);