From 1f5c4d470e14c265e3fd3e7be913f675db6e2b30 Mon Sep 17 00:00:00 2001 From: teo_sarca Date: Tue, 29 Jan 2008 13:23:43 +0000 Subject: [PATCH] BF [ 1874419 ] JDBC Statement not close in a finally block --- .../src/org/compiere/apps/wf/WFActivity.java | 32 ++++++------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/client/src/org/compiere/apps/wf/WFActivity.java b/client/src/org/compiere/apps/wf/WFActivity.java index a0e20d44c1..6e83744e3d 100644 --- a/client/src/org/compiere/apps/wf/WFActivity.java +++ b/client/src/org/compiere/apps/wf/WFActivity.java @@ -287,6 +287,7 @@ public class WFActivity extends CPanel //+ ") ORDER BY a.Priority DESC, Created"; int AD_User_ID = Env.getAD_User_ID(Env.getCtx()); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); @@ -294,25 +295,19 @@ public class WFActivity extends CPanel pstmt.setInt (2, AD_User_ID); pstmt.setInt (3, AD_User_ID); pstmt.setInt (4, AD_User_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) { count = rs.getInt(1); } - rs.close(); } 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; } return count; @@ -344,6 +339,7 @@ public class WFActivity extends CPanel + ") ORDER BY a.Priority DESC, Created"; int AD_User_ID = Env.getAD_User_ID(Env.getCtx()); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); @@ -351,7 +347,7 @@ public class WFActivity extends CPanel pstmt.setInt (2, AD_User_ID); pstmt.setInt (3, AD_User_ID); pstmt.setInt (4, AD_User_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { list.add (new MWFActivity(Env.getCtx(), rs, null)); @@ -361,23 +357,15 @@ public class WFActivity extends CPanel break; } } - 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_activities = new MWFActivity[list.size ()]; list.toArray (m_activities);