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

organize imports
This commit is contained in:
Redhuan D. Oon 2008-02-19 14:20:31 +00:00
parent ccfe6939ce
commit 4c589f7007
1 changed files with 36 additions and 62 deletions

View File

@ -16,14 +16,21 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import java.io.*; import java.io.File;
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.print.*; import java.util.ArrayList;
import org.compiere.process.*; import java.util.Properties;
import org.compiere.util.*; import java.util.logging.Level;
import org.compiere.print.ReportEngine;
import org.compiere.process.DocAction;
import org.compiere.process.DocumentEngine;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Msg;
/** /**
* Order Model. * Order Model.
@ -601,35 +608,27 @@ public class MOrder extends X_C_Order implements DocAction
if (orderClause != null) if (orderClause != null)
sql.append(" ").append(orderClause); sql.append(" ").append(orderClause);
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
pstmt.setInt(1, getC_Order_ID()); pstmt.setInt(1, getC_Order_ID());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
MOrderLine ol = new MOrderLine(getCtx(), rs, get_TrxName()); MOrderLine ol = new MOrderLine(getCtx(), rs, get_TrxName());
ol.setHeaderInfo (this); ol.setHeaderInfo (this);
list.add(ol); list.add(ol);
} }
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);
} }
finally finally
{ {
try DB.close(rs, pstmt);
{ rs = null; pstmt = null;
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
} }
// //
MOrderLine[] lines = new MOrderLine[list.size ()]; MOrderLine[] lines = new MOrderLine[list.size ()];
@ -762,31 +761,23 @@ public class MOrder extends X_C_Order implements DocAction
"WHERE o.C_Order_ID=? " + "WHERE o.C_Order_ID=? " +
"ORDER BY i.Created DESC"; "ORDER BY i.Created DESC";
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, getC_Order_ID()); pstmt.setInt(1, getC_Order_ID());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
list.add(new MInvoice(getCtx(), rs, get_TrxName())); list.add(new MInvoice(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);
} }
finally finally
{ {
try DB.close(rs, pstmt);
{ rs = null; pstmt = null;
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
} }
// //
MInvoice[] retValue = new MInvoice[list.size()]; MInvoice[] retValue = new MInvoice[list.size()];
@ -801,36 +792,27 @@ public class MOrder extends X_C_Order implements DocAction
public int getC_Invoice_ID() public int getC_Invoice_ID()
{ {
int C_Invoice_ID = 0; int C_Invoice_ID = 0;
ArrayList list = new ArrayList(); String sql = "SELECT C_Invoice_ID FROM C_Invoice "
String sql = "SELECT C_Invoice_ID FROM C_Invoice "
+ "WHERE C_Order_ID=? AND DocStatus IN ('CO','CL') " + "WHERE C_Order_ID=? AND DocStatus IN ('CO','CL') "
+ "ORDER BY Created DESC"; + "ORDER BY Created DESC";
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, getC_Order_ID()); pstmt.setInt(1, getC_Order_ID());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
C_Invoice_ID = rs.getInt(1); C_Invoice_ID = rs.getInt(1);
rs.close(); }
pstmt.close();
pstmt = null;
}
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, "getC_Invoice_ID", e); log.log(Level.SEVERE, "getC_Invoice_ID", e);
} }
finally finally
{ {
try DB.close(rs, pstmt);
{ rs = null; pstmt = null;
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
} }
return C_Invoice_ID; return C_Invoice_ID;
} // getC_Invoice_ID } // getC_Invoice_ID
@ -851,31 +833,23 @@ public class MOrder extends X_C_Order implements DocAction
"ORDER BY io.Created DESC"; "ORDER BY io.Created DESC";
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, getC_Order_ID()); pstmt.setInt(1, getC_Order_ID());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
list.add(new MInOut(getCtx(), rs, get_TrxName())); list.add(new MInOut(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);
} }
finally finally
{ {
try DB.close(rs, pstmt);
{ rs = null; pstmt = null;
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
} }
// //
MInOut[] retValue = new MInOut[list.size()]; MInOut[] retValue = new MInOut[list.size()];