From c2941041fece6b5b5947587060869dbea7dd43bb Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 23 Jan 2013 16:05:42 -0800 Subject: [PATCH] IDEMPIERE-568 Review proper closing of JDBC statements and resultsets --- .../src/org/compiere/model/MTab.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MTab.java b/org.adempiere.base/src/org/compiere/model/MTab.java index 4ce7bfa47c..ca83b48527 100644 --- a/org.adempiere.base/src/org/compiere/model/MTab.java +++ b/org.adempiere.base/src/org/compiere/model/MTab.java @@ -129,30 +129,23 @@ public class MTab extends X_AD_Tab String sql = "SELECT * FROM AD_Field WHERE AD_Tab_ID=? ORDER BY SeqNo"; ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, trxName); pstmt.setInt (1, getAD_Tab_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MField (getCtx(), rs, trxName)); - 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_fields = new MField[list.size ()]; @@ -191,22 +184,27 @@ public class MTab extends X_AD_Tab public static int getTab_ID(int AD_Window_ID , String TabName) { int retValue = 0; String SQL = "SELECT AD_Tab_ID FROM AD_Tab WHERE AD_Window_ID= ? AND Name = ?"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(SQL, null); + pstmt = DB.prepareStatement(SQL, null); pstmt.setInt(1, AD_Window_ID); pstmt.setString(2, TabName); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) retValue = rs.getInt(1); - rs.close(); - pstmt.close(); } catch (SQLException e) { s_log.log(Level.SEVERE, SQL, e); retValue = -1; } + finally + { + DB.close(rs, pstmt); + rs = null; pstmt = null; + } return retValue; } //end vpj-cd e-evolution