From 7a7bf13e744dbdea50ce82da03c733aa8d3a551a Mon Sep 17 00:00:00 2001 From: "Redhuan D. Oon" Date: Sat, 9 Feb 2008 12:34:32 +0000 Subject: [PATCH] *BF [ 1874419 ] JDBC Statement not close in a finally block - fixed in 2 spots --- base/src/org/compiere/model/MRole.java | 63 +++++++++----------------- 1 file changed, 21 insertions(+), 42 deletions(-) diff --git a/base/src/org/compiere/model/MRole.java b/base/src/org/compiere/model/MRole.java index a30df136d7..f06b23b904 100644 --- a/base/src/org/compiere/model/MRole.java +++ b/base/src/org/compiere/model/MRole.java @@ -145,31 +145,24 @@ public final class MRole extends X_AD_Role { String sql = "SELECT * FROM AD_Role WHERE AD_Client_ID=?"; ArrayList list = new ArrayList (); - PreparedStatement pstmt = null; + PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, Env.getAD_Client_ID(ctx)); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MRole(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; } MRole[] retValue = new MRole[list.size ()]; list.toArray (retValue); @@ -188,30 +181,23 @@ public final class MRole extends X_AD_Role if (whereClause != null && whereClause.length() > 0) sql += " WHERE " + whereClause; ArrayList list = new ArrayList (); - PreparedStatement pstmt = null; + PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MRole(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; } MRole[] retValue = new MRole[list.size ()]; list.toArray (retValue); @@ -789,36 +775,29 @@ public final class MRole extends X_AD_Role + "WHERE IsActive='Y' AND AD_Org_ID IN (SELECT Node_ID FROM " + tree.getNodeTableName() + " WHERE AD_Tree_ID=? AND Parent_ID=? AND IsActive='Y')"; - PreparedStatement pstmt = null; + PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, tree.getAD_Tree_ID()); pstmt.setInt(2, org.getAD_Org_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { int AD_Client_ID = rs.getInt(1); int AD_Org_ID = rs.getInt(2); loadOrgAccessAdd (list, new OrgAccess(AD_Client_ID, AD_Org_ID, oa.readOnly)); } - 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; } } // loadOrgAccessAdd