IDEMPIERE-568 Review proper closing of JDBC statements and resultsetsHG: Enter commit message. Lines beginning with 'HG:' are removed.

This commit is contained in:
Carlos Ruiz 2013-01-18 11:34:42 -08:00
parent 0ebc6fab41
commit 2b3f71e48c
1 changed files with 10 additions and 24 deletions

View File

@ -476,6 +476,7 @@ public class MCost extends X_M_Cost
sql.append(" ORDER BY i.DateInvoiced DESC, il.Line DESC"); sql.append(" ORDER BY i.DateInvoiced DESC, il.Line DESC");
// //
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql.toString(), product.get_TrxName()); pstmt = DB.prepareStatement (sql.toString(), product.get_TrxName());
@ -485,26 +486,18 @@ public class MCost extends X_M_Cost
pstmt.setInt (3, AD_Org_ID); pstmt.setInt (3, AD_Org_ID);
else if (M_ASI_ID != 0) else if (M_ASI_ID != 0)
pstmt.setInt(3, M_ASI_ID); pstmt.setInt(3, M_ASI_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
if (rs.next ()) if (rs.next ())
retValue = rs.getBigDecimal(1); retValue = rs.getBigDecimal(1);
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
s_log.log (Level.SEVERE, sql.toString(), e); s_log.log (Level.SEVERE, sql.toString(), e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close (); rs = null; pstmt = null;
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
if (retValue != null) if (retValue != null)
@ -653,11 +646,12 @@ public class MCost extends X_M_Cost
+ " AND EXISTS (SELECT * FROM M_CostDetail cd " + " AND EXISTS (SELECT * FROM M_CostDetail cd "
+ "WHERE p.M_Product_ID=cd.M_Product_ID AND Processed='N')"; + "WHERE p.M_Product_ID=cd.M_Product_ID AND Processed='N')";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, trxNameUsed); pstmt = DB.prepareStatement (sql, trxNameUsed);
pstmt.setInt (1, client.getAD_Client_ID()); pstmt.setInt (1, client.getAD_Client_ID());
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
MProduct product = new MProduct (client.getCtx(), rs, trxNameUsed); MProduct product = new MProduct (client.getCtx(), rs, trxNameUsed);
@ -668,24 +662,16 @@ public class MCost extends X_M_Cost
s_log.info(product.getName() + " = " + cost); s_log.info(product.getName() + " = " + cost);
} }
} }
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
s_log.log (Level.SEVERE, sql, e); s_log.log (Level.SEVERE, sql, e);
success = false; success = false;
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close (); rs = null; pstmt = null;
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
// Transaction // Transaction
if (trx != null) if (trx != null)