From c4f0c7a1fa3ef8b99a2519bb2a4a8bd8da38ea33 Mon Sep 17 00:00:00 2001 From: "Redhuan D. Oon" Date: Sat, 9 Feb 2008 11:08:45 +0000 Subject: [PATCH] *BF [ 1874419 ] JDBC Statement not close in a finally block - fixed in 2 spots *Organize imports --- base/src/org/compiere/model/MChat.java | 72 +++++++++++++------------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/base/src/org/compiere/model/MChat.java b/base/src/org/compiere/model/MChat.java index a5a1f5308c..b294fae5c2 100644 --- a/base/src/org/compiere/model/MChat.java +++ b/base/src/org/compiere/model/MChat.java @@ -16,12 +16,22 @@ *****************************************************************************/ package org.compiere.model; -import java.sql.*; -import java.text.*; -import java.util.*; -import java.util.logging.*; -import org.apache.ecs.xhtml.*; -import org.compiere.util.*; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.Timestamp; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Properties; +import java.util.logging.Level; + +import org.apache.ecs.xhtml.b; +import org.apache.ecs.xhtml.hr; +import org.apache.ecs.xhtml.p; +import org.compiere.util.CLogger; +import org.compiere.util.DB; +import org.compiere.util.DisplayType; +import org.compiere.util.Env; +import org.compiere.util.Util; /** * Chat Model @@ -44,35 +54,29 @@ public class MChat extends X_CM_Chat // String sql = "SELECT * FROM CM_Chat " + "WHERE AD_Client_ID=? AND AD_Table_ID=? ORDER BY Record_ID"; - PreparedStatement pstmt = null; + PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, AD_Client_ID); pstmt.setInt (2, AD_Table_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { list.add (new MChat (ctx, rs, null)); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; - } + finally + { + DB.close(rs, pstmt); + rs = null; pstmt = null; + } + // MChat[] retValue = new MChat[list.size()]; list.toArray (retValue); @@ -147,34 +151,28 @@ public class MChat extends X_CM_Chat return m_entries; ArrayList list = new ArrayList(); String sql = "SELECT * FROM CM_ChatEntry WHERE CM_Chat_ID=? ORDER BY Created"; - PreparedStatement pstmt = null; + PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, getCM_Chat_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { list.add (new MChatEntry (getCtx(), rs, get_TrxName())); } - rs.close (); - pstmt.close (); - pstmt = null; - } + } catch (Exception e) { log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; - } + finally + { + DB.close(rs, pstmt); + rs = null; pstmt = null; + } + // m_entries = new MChatEntry[list.size ()]; list.toArray (m_entries);