From 8219afb5ca861a8a834d5af24d0c5f44633a3349 Mon Sep 17 00:00:00 2001 From: teo_sarca Date: Fri, 15 Feb 2008 16:15:59 +0000 Subject: [PATCH] MCash: * BF [ 1874419 ] JDBC Statement not close in a finally block * organized imports --- base/src/org/compiere/model/MCash.java | 75 +++++++++++--------------- 1 file changed, 32 insertions(+), 43 deletions(-) diff --git a/base/src/org/compiere/model/MCash.java b/base/src/org/compiere/model/MCash.java index 6dd377ca64..a40db0e48d 100644 --- a/base/src/org/compiere/model/MCash.java +++ b/base/src/org/compiere/model/MCash.java @@ -16,13 +16,23 @@ *****************************************************************************/ package org.compiere.model; -import java.io.*; -import java.math.*; -import java.sql.*; -import java.util.*; -import java.util.logging.*; -import org.compiere.process.*; -import org.compiere.util.*; +import java.io.File; +import java.math.BigDecimal; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Properties; +import java.util.logging.Level; + +import org.compiere.process.DocAction; +import org.compiere.process.DocumentEngine; +import org.compiere.util.CLogger; +import org.compiere.util.DB; +import org.compiere.util.DisplayType; +import org.compiere.util.Env; +import org.compiere.util.Msg; +import org.compiere.util.TimeUtil; /** * Cash Journal Model @@ -59,32 +69,25 @@ public class MCash extends X_C_Cash implements DocAction + " AND cb.C_Currency_ID=?)"; // #3 PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, trxName); pstmt.setInt (1, AD_Org_ID); pstmt.setTimestamp (2, TimeUtil.getDay(dateAcct)); pstmt.setInt (3, C_Currency_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) retValue = new MCash (ctx, rs, trxName); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_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; } if (retValue != null) return retValue; @@ -121,31 +124,24 @@ public class MCash extends X_C_Cash implements DocAction + " AND TRUNC(c.StatementDate)=?" // #2 + " AND c.Processed='N'"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, trxName); pstmt.setInt (1, C_CashBook_ID); pstmt.setTimestamp (2, TimeUtil.getDay(dateAcct)); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) retValue = new MCash (ctx, rs, trxName); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_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; } if (retValue != null) return retValue; @@ -249,30 +245,23 @@ public class MCash extends X_C_Cash implements DocAction ArrayList list = new ArrayList(); String sql = "SELECT * FROM C_CashLine WHERE C_Cash_ID=? ORDER BY Line"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getC_Cash_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MCashLine (getCtx(), rs, get_TrxName())); - 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_lines = new MCashLine[list.size ()];