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

organize imports
This commit is contained in:
Redhuan D. Oon 2008-02-19 12:48:43 +00:00
parent d906d61243
commit 6bf804d6df
1 changed files with 39 additions and 56 deletions

View File

@ -16,12 +16,23 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.process; package org.compiere.process;
import java.math.*; import java.math.BigDecimal;
import java.sql.*; import java.sql.PreparedStatement;
import java.util.*; import java.sql.ResultSet;
import org.compiere.model.*; import java.sql.Timestamp;
import java.util.logging.*; import java.util.ArrayList;
import org.compiere.util.*; import java.util.logging.Level;
import org.compiere.model.MAllocationHdr;
import org.compiere.model.MAllocationLine;
import org.compiere.model.MClient;
import org.compiere.model.MInvoice;
import org.compiere.model.MPaySelectionCheck;
import org.compiere.model.MPaySelectionLine;
import org.compiere.model.MPayment;
import org.compiere.util.AdempiereSystemError;
import org.compiere.util.DB;
import org.compiere.util.Env;
/** /**
* Automatic Allocation Process * Automatic Allocation Process
@ -98,11 +109,12 @@ public class AllocationAuto extends SvrProcess
{ {
String sql = "SELECT C_BPartner_ID FROM C_BPartner WHERE C_BP_Group_ID=? ORDER BY Value"; String sql = "SELECT C_BPartner_ID FROM C_BPartner WHERE C_BP_Group_ID=? ORDER BY Value";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt = DB.prepareStatement (sql, get_TrxName());
pstmt.setInt (1, p_C_BP_Group_ID); pstmt.setInt (1, p_C_BP_Group_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
int C_BPartner_ID = rs.getInt(1); int C_BPartner_ID = rs.getInt(1);
@ -114,34 +126,27 @@ public class AllocationAuto extends SvrProcess
commit(); commit();
} }
} }
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;
} }
} }
else else
{ {
String sql = "SELECT C_BPartner_ID FROM C_BPartner WHERE AD_Client_ID=? ORDER BY Value"; String sql = "SELECT C_BPartner_ID FROM C_BPartner WHERE AD_Client_ID=? ORDER BY Value";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt = DB.prepareStatement (sql, get_TrxName());
pstmt.setInt (1, Env.getAD_Client_ID(getCtx())); pstmt.setInt (1, Env.getAD_Client_ID(getCtx()));
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
int C_BPartner_ID = rs.getInt(1); int C_BPartner_ID = rs.getInt(1);
@ -153,23 +158,15 @@ public class AllocationAuto extends SvrProcess
commit(); commit();
} }
} }
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;
} }
} }
// //
@ -270,11 +267,12 @@ public class AllocationAuto extends SvrProcess
sql += "AND IsReceipt='Y' "; sql += "AND IsReceipt='Y' ";
sql += "ORDER BY DateTrx"; sql += "ORDER BY DateTrx";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt = DB.prepareStatement (sql, get_TrxName());
pstmt.setInt (1, C_BPartner_ID); pstmt.setInt (1, C_BPartner_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
MPayment payment = new MPayment (getCtx(), rs, get_TrxName()); MPayment payment = new MPayment (getCtx(), rs, get_TrxName());
@ -287,23 +285,15 @@ public class AllocationAuto extends SvrProcess
else else
list.add (payment); list.add (payment);
} }
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_payments = new MPayment[list.size ()]; m_payments = new MPayment[list.size ()];
list.toArray (m_payments); list.toArray (m_payments);
@ -326,11 +316,12 @@ public class AllocationAuto extends SvrProcess
sql += "AND IsSOTrx='Y' "; sql += "AND IsSOTrx='Y' ";
sql += "ORDER BY DateInvoiced";; sql += "ORDER BY DateInvoiced";;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt = DB.prepareStatement (sql, get_TrxName());
pstmt.setInt (1, C_BPartner_ID); pstmt.setInt (1, C_BPartner_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
MInvoice invoice = new MInvoice (getCtx(), rs, get_TrxName()); MInvoice invoice = new MInvoice (getCtx(), rs, get_TrxName());
@ -342,23 +333,15 @@ public class AllocationAuto extends SvrProcess
else else
list.add (invoice); list.add (invoice);
} }
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_invoices = new MInvoice[list.size ()]; m_invoices = new MInvoice[list.size ()];
list.toArray (m_invoices); list.toArray (m_invoices);