*BF [ 1874419 ] JDBC Statement not close in a finally block

Organize Imports
This commit is contained in:
Redhuan D. Oon 2008-02-08 10:02:07 +00:00
parent 7e51491b76
commit 6400fd0d45
1 changed files with 23 additions and 32 deletions

View File

@ -16,12 +16,17 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.process; package org.compiere.process;
import java.awt.geom.*; import java.awt.geom.IllegalPathStateException;
import java.math.*; import java.math.BigDecimal;
import java.sql.*; import java.sql.PreparedStatement;
import java.util.logging.*; import java.sql.ResultSet;
import org.compiere.model.*; import java.sql.Timestamp;
import org.compiere.util.*; import java.util.logging.Level;
import org.compiere.model.MBPartner;
import org.compiere.model.MOrder;
import org.compiere.model.MOrderLine;
import org.compiere.util.DB;
/** /**
* Generate PO from Sales Order * Generate PO from Sales Order
@ -114,6 +119,7 @@ public class OrderPOCreate extends SvrProcess
sql += "AND TRUNC(o.DateOrdered) <= ?"; sql += "AND TRUNC(o.DateOrdered) <= ?";
} }
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
int counter = 0; int counter = 0;
try try
{ {
@ -139,28 +145,20 @@ public class OrderPOCreate extends SvrProcess
else if (p_DateOrdered_From == null && p_DateOrdered_To != null) else if (p_DateOrdered_From == null && p_DateOrdered_To != null)
pstmt.setTimestamp(index++, p_DateOrdered_To); pstmt.setTimestamp(index++, p_DateOrdered_To);
} }
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
counter += createPOFromSO (new MOrder (getCtx(), rs, get_TrxName())); counter += createPOFromSO (new MOrder (getCtx(), rs, get_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;
} }
if (counter == 0) if (counter == 0)
log.fine(sql); log.fine(sql);
@ -190,12 +188,13 @@ public class OrderPOCreate extends SvrProcess
+ "WHERE ol.C_Order_ID=? AND po.IsCurrentVendor='Y' " + "WHERE ol.C_Order_ID=? AND po.IsCurrentVendor='Y' "
+ "ORDER BY 1"; + "ORDER BY 1";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
MOrder po = null; MOrder po = null;
try try
{ {
pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt = DB.prepareStatement (sql, get_TrxName());
pstmt.setInt (1, so.getC_Order_ID()); pstmt.setInt (1, so.getC_Order_ID());
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
// New Order // New Order
@ -227,23 +226,15 @@ public class OrderPOCreate extends SvrProcess
} }
} }
} }
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;
} }
// Set Reference to PO // Set Reference to PO
if (counter == 1 && po != null) if (counter == 1 && po != null)