From 37bfc101b5a24e90f3ca9c757709d915ce9f5bae Mon Sep 17 00:00:00 2001 From: "Redhuan D. Oon" Date: Fri, 8 Feb 2008 08:43:21 +0000 Subject: [PATCH] *BF [ 1874419 ] JDBC Statement not close in a finally block *Organize imports --- base/src/org/compiere/MigrateData.java | 33 +++++++------- client/src/org/compiere/apps/ARequest.java | 46 +++++++++++++++----- install/src/org/compiere/install/Config.java | 16 +++---- 3 files changed, 54 insertions(+), 41 deletions(-) diff --git a/base/src/org/compiere/MigrateData.java b/base/src/org/compiere/MigrateData.java index b46eac65c5..60187a4192 100644 --- a/base/src/org/compiere/MigrateData.java +++ b/base/src/org/compiere/MigrateData.java @@ -16,13 +16,16 @@ *****************************************************************************/ package org.compiere; -import java.sql.*; -import java.util.*; -import java.util.logging.*; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.Properties; +import java.util.logging.Level; -import org.compiere.util.*; -import org.compiere.model.*; -import org.compiere.print.*; +import org.compiere.model.MProductDownload; +import org.compiere.print.PrintFormatUtil; +import org.compiere.util.CLogger; +import org.compiere.util.DB; +import org.compiere.util.Env; /** * Migrate Data @@ -65,10 +68,11 @@ public class MigrateData + "FROM M_Product " + "WHERE DownloadURL IS NOT NULL"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { int AD_Client_ID = rs.getInt(1); @@ -97,24 +101,17 @@ public class MigrateData else log.warning("Product Download not created M_Product_ID=" + M_Product_ID); } - 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; } + log.info("#" + count); } // release252c diff --git a/client/src/org/compiere/apps/ARequest.java b/client/src/org/compiere/apps/ARequest.java index 38de7e7282..424fec3c97 100644 --- a/client/src/org/compiere/apps/ARequest.java +++ b/client/src/org/compiere/apps/ARequest.java @@ -16,14 +16,33 @@ *****************************************************************************/ package org.compiere.apps; -import java.awt.event.*; -import java.sql.*; -import java.util.logging.*; -import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.logging.Level; -import org.compiere.model.*; -import org.compiere.swing.*; -import org.compiere.util.*; +import javax.swing.JComponent; +import javax.swing.JPopupMenu; + +import org.compiere.model.GridTab; +import org.compiere.model.MAsset; +import org.compiere.model.MBPartner; +import org.compiere.model.MCampaign; +import org.compiere.model.MInOut; +import org.compiere.model.MInvoice; +import org.compiere.model.MOrder; +import org.compiere.model.MPayment; +import org.compiere.model.MProduct; +import org.compiere.model.MProject; +import org.compiere.model.MQuery; +import org.compiere.model.MRMA; +import org.compiere.model.MUser; +import org.compiere.swing.CMenuItem; +import org.compiere.util.CLogger; +import org.compiere.util.DB; +import org.compiere.util.Env; +import org.compiere.util.Msg; /** @@ -113,10 +132,11 @@ public class ARequest implements ActionListener + " GROUP BY Processed " + "ORDER BY Processed DESC"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { if ("Y".equals(rs.getString(1))) @@ -124,9 +144,6 @@ public class ARequest implements ActionListener else activeCount += rs.getInt(2); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { @@ -142,7 +159,12 @@ public class ARequest implements ActionListener { pstmt = null; } - + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // if (activeCount > 0) { diff --git a/install/src/org/compiere/install/Config.java b/install/src/org/compiere/install/Config.java index 34832782f0..ce7cbd3cf5 100644 --- a/install/src/org/compiere/install/Config.java +++ b/install/src/org/compiere/install/Config.java @@ -131,33 +131,27 @@ public abstract class Config { String sql = "SELECT WebContext FROM W_Store WHERE IsActive='Y'"; Statement stmt = null; + ResultSet rs = null; StringBuffer result = new StringBuffer(); try { stmt = con.createStatement(); - ResultSet rs = stmt.executeQuery(sql); + rs = stmt.executeQuery(sql); while (rs.next ()) { if (result.length() > 0) result.append(","); result.append(rs.getString(1)); } - rs.close (); - stmt.close (); - stmt = null; } catch (Exception e) { log.severe(e.toString()); } - try - { - if (stmt != null) - stmt.close (); - stmt = null; - } - catch (Exception e) + finally { + DB.close(rs, stmt); + rs = null; stmt = null; } return result.toString();