From 609f2e8f0e9cbddd5cb15a6127c88b1d7c902bab Mon Sep 17 00:00:00 2001 From: teo_sarca Date: Sat, 26 Jan 2008 10:05:42 +0000 Subject: [PATCH] BF [ 1874419 ] JDBC Statement not close in a finally block --- .../apps/search/PAttributeInstance.java | 36 ++++++------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/client/src/org/compiere/apps/search/PAttributeInstance.java b/client/src/org/compiere/apps/search/PAttributeInstance.java index 9037a41a8c..c4e04bdb5c 100644 --- a/client/src/org/compiere/apps/search/PAttributeInstance.java +++ b/client/src/org/compiere/apps/search/PAttributeInstance.java @@ -184,12 +184,13 @@ public class PAttributeInstance extends CDialog + " ON (bp.C_BPartner_ID=bpp.C_BPartner_ID AND bpp.M_Product_ID=?) " + "WHERE bp.C_BPartner_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, m_M_Product_ID); pstmt.setInt(2, C_BPartner_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { ShelfLifeMinPct = rs.getInt(1); // BP @@ -198,23 +199,14 @@ public class PAttributeInstance extends CDialog ShelfLifeMinDays = pct; ShelfLifeMinDays = rs.getInt(3); } - 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; } if (ShelfLifeMinPct > 0) { @@ -258,31 +250,23 @@ public class PAttributeInstance extends CDialog // log.finest(sql); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, m_M_Product_ID); if (m_M_Warehouse_ID != 0) pstmt.setInt(2, m_M_Warehouse_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); m_table.loadTable(rs); - 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; } enableButtons(); } // refresh