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

organize imports
This commit is contained in:
Redhuan D. Oon 2008-02-19 10:52:17 +00:00
parent 0be4012cfb
commit 5e752fa1fb
1 changed files with 38 additions and 71 deletions

View File

@ -16,11 +16,17 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import java.math.*; import java.math.BigDecimal;
import java.sql.*; import java.sql.PreparedStatement;
import java.util.*; import java.sql.ResultSet;
import java.util.logging.*; import java.sql.Timestamp;
import org.compiere.util.*; import java.util.ArrayList;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
/** /**
* Match Invoice (Receipt<>Invoice) Model. * Match Invoice (Receipt<>Invoice) Model.
@ -50,31 +56,24 @@ public class MMatchInv extends X_M_MatchInv
String sql = "SELECT * FROM M_MatchInv WHERE M_InOutLine_ID=? AND C_InvoiceLine_ID=?"; String sql = "SELECT * FROM M_MatchInv WHERE M_InOutLine_ID=? AND C_InvoiceLine_ID=?";
ArrayList<MMatchInv> list = new ArrayList<MMatchInv>(); ArrayList<MMatchInv> list = new ArrayList<MMatchInv>();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, trxName); pstmt = DB.prepareStatement (sql, trxName);
pstmt.setInt (1, M_InOutLine_ID); pstmt.setInt (1, M_InOutLine_ID);
pstmt.setInt (2, C_InvoiceLine_ID); pstmt.setInt (2, C_InvoiceLine_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
list.add (new MMatchInv (ctx, rs, trxName)); list.add (new MMatchInv (ctx, rs, trxName));
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);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close (); rs = null; pstmt = null;
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
MMatchInv[] retValue = new MMatchInv[list.size()]; MMatchInv[] retValue = new MMatchInv[list.size()];
list.toArray (retValue); list.toArray (retValue);
@ -97,30 +96,23 @@ public class MMatchInv extends X_M_MatchInv
String sql = "SELECT * FROM M_MatchInv WHERE C_InvoiceLine_ID=?"; String sql = "SELECT * FROM M_MatchInv WHERE C_InvoiceLine_ID=?";
ArrayList<MMatchInv> list = new ArrayList<MMatchInv>(); ArrayList<MMatchInv> list = new ArrayList<MMatchInv>();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, trxName); pstmt = DB.prepareStatement (sql, trxName);
pstmt.setInt (1, C_InvoiceLine_ID); pstmt.setInt (1, C_InvoiceLine_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
list.add (new MMatchInv (ctx, rs, trxName)); list.add (new MMatchInv (ctx, rs, trxName));
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);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close (); rs = null; pstmt = null;
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
MMatchInv[] retValue = new MMatchInv[list.size()]; MMatchInv[] retValue = new MMatchInv[list.size()];
list.toArray (retValue); list.toArray (retValue);
@ -146,30 +138,23 @@ public class MMatchInv extends X_M_MatchInv
+ "WHERE l.M_InOut_ID=?"; + "WHERE l.M_InOut_ID=?";
ArrayList<MMatchInv> list = new ArrayList<MMatchInv>(); ArrayList<MMatchInv> list = new ArrayList<MMatchInv>();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, trxName); pstmt = DB.prepareStatement (sql, trxName);
pstmt.setInt (1, M_InOut_ID); pstmt.setInt (1, M_InOut_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
list.add (new MMatchInv (ctx, rs, trxName)); list.add (new MMatchInv (ctx, rs, trxName));
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);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close (); rs = null; pstmt = null;
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
MMatchInv[] retValue = new MMatchInv[list.size()]; MMatchInv[] retValue = new MMatchInv[list.size()];
list.toArray (retValue); list.toArray (retValue);
@ -194,30 +179,23 @@ public class MMatchInv extends X_M_MatchInv
+ "WHERE il.C_Invoice_ID=?"; + "WHERE il.C_Invoice_ID=?";
ArrayList<MMatchInv> list = new ArrayList<MMatchInv>(); ArrayList<MMatchInv> list = new ArrayList<MMatchInv>();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, trxName); pstmt = DB.prepareStatement (sql, trxName);
pstmt.setInt (1, C_Invoice_ID); pstmt.setInt (1, C_Invoice_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
list.add (new MMatchInv (ctx, rs, trxName)); list.add (new MMatchInv (ctx, rs, trxName));
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);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close (); rs = null; pstmt = null;
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
MMatchInv[] retValue = new MMatchInv[list.size()]; MMatchInv[] retValue = new MMatchInv[list.size()];
list.toArray (retValue); list.toArray (retValue);
@ -325,16 +303,14 @@ public class MMatchInv extends X_M_MatchInv
+ " INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID) " + " INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID) "
+ "WHERE C_InvoiceLine_ID=?"; + "WHERE C_InvoiceLine_ID=?";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, null); pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, getC_InvoiceLine_ID()); pstmt.setInt (1, getC_InvoiceLine_ID());
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
if (rs.next ()) if (rs.next ())
invoiceDate = rs.getTimestamp(1); invoiceDate = rs.getTimestamp(1);
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
@ -348,29 +324,20 @@ public class MMatchInv extends X_M_MatchInv
{ {
pstmt = DB.prepareStatement (sql, null); pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, getM_InOutLine_ID()); pstmt.setInt (1, getM_InOutLine_ID());
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
if (rs.next ()) if (rs.next ())
shipDate = rs.getTimestamp(1); shipDate = rs.getTimestamp(1);
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 (invoiceDate == null) if (invoiceDate == null)
return shipDate; return shipDate;
if (shipDate == null) if (shipDate == null)