From 1b5a943509e4c5c3d5b38a103187d0db008d5766 Mon Sep 17 00:00:00 2001 From: teo_sarca Date: Wed, 30 Jan 2008 08:54:31 +0000 Subject: [PATCH] BF [ 1874419 ] JDBC Statement not close in a finally block - for MUserQuery --- base/src/org/compiere/model/MUserQuery.java | 34 ++++++--------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/base/src/org/compiere/model/MUserQuery.java b/base/src/org/compiere/model/MUserQuery.java index 1121945959..49d53844db 100644 --- a/base/src/org/compiere/model/MUserQuery.java +++ b/base/src/org/compiere/model/MUserQuery.java @@ -45,31 +45,24 @@ public class MUserQuery extends X_AD_UserQuery int AD_Client_ID = Env.getAD_Client_ID (ctx); ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, AD_Client_ID); pstmt.setInt (2, AD_Tab_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next ()) list.add(new MUserQuery (ctx, rs, null)); - 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; } MUserQuery[] retValue = new MUserQuery[list.size()]; list.toArray(retValue); @@ -95,32 +88,25 @@ public class MUserQuery extends X_AD_UserQuery name = "%"; MUserQuery retValue = null; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, AD_Client_ID); pstmt.setInt (2, AD_Tab_ID); pstmt.setString (3, name.toUpperCase()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) retValue = new MUserQuery (ctx, rs, null); - 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; } return retValue; } // get