IDEMPIERE-568 Review proper closing of JDBC statements and resultsets

This commit is contained in:
Carlos Ruiz 2013-01-23 16:05:42 -08:00
parent 3eb6bc9151
commit c2941041fe
1 changed files with 14 additions and 16 deletions

View File

@ -129,30 +129,23 @@ public class MTab extends X_AD_Tab
String sql = "SELECT * FROM AD_Field WHERE AD_Tab_ID=? ORDER BY SeqNo"; String sql = "SELECT * FROM AD_Field WHERE AD_Tab_ID=? ORDER BY SeqNo";
ArrayList<MField> list = new ArrayList<MField>(); ArrayList<MField> list = new ArrayList<MField>();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, trxName); pstmt = DB.prepareStatement (sql, trxName);
pstmt.setInt (1, getAD_Tab_ID()); pstmt.setInt (1, getAD_Tab_ID());
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
list.add (new MField (getCtx(), rs, trxName)); list.add (new MField (getCtx(), rs, trxName));
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close (); rs = null; pstmt = null;
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
// //
m_fields = new MField[list.size ()]; 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) { public static int getTab_ID(int AD_Window_ID , String TabName) {
int retValue = 0; int retValue = 0;
String SQL = "SELECT AD_Tab_ID FROM AD_Tab WHERE AD_Window_ID= ? AND Name = ?"; String SQL = "SELECT AD_Tab_ID FROM AD_Tab WHERE AD_Window_ID= ? AND Name = ?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
PreparedStatement pstmt = DB.prepareStatement(SQL, null); pstmt = DB.prepareStatement(SQL, null);
pstmt.setInt(1, AD_Window_ID); pstmt.setInt(1, AD_Window_ID);
pstmt.setString(2, TabName); pstmt.setString(2, TabName);
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
retValue = rs.getInt(1); retValue = rs.getInt(1);
rs.close();
pstmt.close();
} }
catch (SQLException e) catch (SQLException e)
{ {
s_log.log(Level.SEVERE, SQL, e); s_log.log(Level.SEVERE, SQL, e);
retValue = -1; retValue = -1;
} }
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return retValue; return retValue;
} }
//end vpj-cd e-evolution //end vpj-cd e-evolution