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

organize imports
This commit is contained in:
Redhuan D. Oon 2008-02-19 12:53:18 +00:00
parent 6f3f7ddfb6
commit cf2793cae1
1 changed files with 15 additions and 17 deletions

View File

@ -16,10 +16,15 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.process; package org.compiere.process;
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.MAllocationHdr;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Trx;
/** /**
* Reset (delete) Allocations * Reset (delete) Allocations
@ -116,6 +121,7 @@ public class AllocationReset extends SvrProcess
+ "WHERE ah.DateAcct BETWEEN p.StartDate AND p.EndDate)"); + "WHERE ah.DateAcct BETWEEN p.StartDate AND p.EndDate)");
// //
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql.toString(), m_trx.getTrxName()); pstmt = DB.prepareStatement (sql.toString(), m_trx.getTrxName());
@ -130,31 +136,23 @@ public class AllocationReset extends SvrProcess
pstmt.setTimestamp(index++, p_DateAcct_From); pstmt.setTimestamp(index++, p_DateAcct_From);
if (p_DateAcct_To != null) if (p_DateAcct_To != null)
pstmt.setTimestamp(index++, p_DateAcct_To); pstmt.setTimestamp(index++, p_DateAcct_To);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
MAllocationHdr hdr = new MAllocationHdr(getCtx(), rs, m_trx.getTrxName()); MAllocationHdr hdr = new MAllocationHdr(getCtx(), rs, m_trx.getTrxName());
if (delete(hdr)) if (delete(hdr))
count++; count++;
} }
rs.close (); }
pstmt.close ();
pstmt = null;
}
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql.toString(), e); log.log(Level.SEVERE, sql.toString(), e);
m_trx.rollback(); m_trx.rollback();
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close (); rs = null; pstmt = null;
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
m_trx.close(); m_trx.close();
return "@Deleted@ #" + count; return "@Deleted@ #" + count;