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

organize imports
This commit is contained in:
Redhuan D. Oon 2008-02-19 10:54:56 +00:00
parent 1d2ac06ad9
commit d906d61243
1 changed files with 27 additions and 39 deletions

View File

@ -16,10 +16,16 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import java.sql.*; import java.sql.PreparedStatement;
import java.util.*; import java.sql.ResultSet;
import java.util.logging.*; import java.sql.SQLException;
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.KeyNamePair;
/** /**
* Product Lot * Product Lot
@ -44,30 +50,24 @@ public class MLot extends X_M_Lot
String sql = "SELECT * FROM M_Lot WHERE M_Product_ID=?"; String sql = "SELECT * FROM M_Lot WHERE M_Product_ID=?";
ArrayList<MLot> list = new ArrayList<MLot>(); ArrayList<MLot> list = new ArrayList<MLot>();
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_Product_ID); pstmt.setInt (1, M_Product_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
list.add (new MLot (ctx, rs, trxName)); list.add (new MLot (ctx, rs, trxName));
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (SQLException ex) catch (SQLException ex)
{ {
s_log.log(Level.SEVERE, sql, ex); s_log.log(Level.SEVERE, sql, ex);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close (); rs = null; pstmt = null;
} }
catch (SQLException ex1)
{
}
pstmt = null;
// //
MLot[] retValue = new MLot[list.size()]; MLot[] retValue = new MLot[list.size()];
list.toArray(retValue); list.toArray(retValue);
@ -87,31 +87,25 @@ public class MLot extends X_M_Lot
String sql = "SELECT * FROM M_Lot WHERE M_Product_ID=? AND Name=?"; String sql = "SELECT * FROM M_Lot WHERE M_Product_ID=? AND Name=?";
MLot retValue = null; MLot retValue = null;
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_Product_ID); pstmt.setInt (1, M_Product_ID);
pstmt.setString(2, lot); pstmt.setString(2, lot);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
retValue = new MLot (ctx, rs, trxName); retValue = new MLot (ctx, rs, trxName);
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (SQLException ex) catch (SQLException ex)
{ {
s_log.log(Level.SEVERE, sql, ex); s_log.log(Level.SEVERE, sql, ex);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close (); rs = null; pstmt = null;
} }
catch (SQLException ex1)
{
}
pstmt = null;
return retValue; return retValue;
} // getProductLot } // getProductLot
@ -126,30 +120,24 @@ public class MLot extends X_M_Lot
String sql = "SELECT M_Lot_ID, Name FROM M_Lot WHERE M_Product_ID=?"; String sql = "SELECT M_Lot_ID, Name FROM M_Lot WHERE M_Product_ID=?";
ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>(); ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
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_Product_ID); pstmt.setInt (1, M_Product_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
list.add (new KeyNamePair (rs.getInt(1), rs.getString(2))); list.add (new KeyNamePair (rs.getInt(1), rs.getString(2)));
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (SQLException ex) catch (SQLException ex)
{ {
s_log.log(Level.SEVERE, sql, ex); s_log.log(Level.SEVERE, sql, ex);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close (); rs = null; pstmt = null;
} }
catch (SQLException ex1)
{
}
pstmt = null;
// //
KeyNamePair[] retValue = new KeyNamePair[list.size()]; KeyNamePair[] retValue = new KeyNamePair[list.size()];
list.toArray(retValue); list.toArray(retValue);