BF [ 1874419 ] JDBC Statement not close in a finally block - fixed for MLocator

This commit is contained in:
teo_sarca 2008-02-03 10:13:06 +00:00
parent e4152c7582
commit 6608962f25
1 changed files with 10 additions and 24 deletions

View File

@ -45,30 +45,23 @@ public class MLocator extends X_M_Locator
+ "WHERE l.M_Warehouse_ID=lx.M_Warehouse_ID AND lx.M_Locator_ID=?) " + "WHERE l.M_Warehouse_ID=lx.M_Warehouse_ID AND lx.M_Locator_ID=?) "
+ "ORDER BY Created"; + "ORDER BY Created";
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_Locator_ID); pstmt.setInt (1, M_Locator_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
retValue = new MLocator (ctx, rs, trxName); retValue = new MLocator (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;
} }
return retValue; return retValue;
@ -91,6 +84,7 @@ public class MLocator extends X_M_Locator
MLocator retValue = null; MLocator retValue = null;
String sql = "SELECT * FROM M_Locator WHERE M_Warehouse_ID=? AND X=? AND Y=? AND Z=?"; String sql = "SELECT * FROM M_Locator WHERE M_Warehouse_ID=? AND X=? AND Y=? AND Z=?";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement(sql, null); pstmt = DB.prepareStatement(sql, null);
@ -98,26 +92,18 @@ public class MLocator extends X_M_Locator
pstmt.setString(2, X); pstmt.setString(2, X);
pstmt.setString(3, Y); pstmt.setString(3, Y);
pstmt.setString(4, Z); pstmt.setString(4, Z);
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
retValue = new MLocator (ctx, rs, null); retValue = new MLocator (ctx, rs, null);
rs.close();
pstmt.close();
pstmt = null;
} }
catch (SQLException ex) catch (SQLException ex)
{ {
s_log.log(Level.SEVERE, "get", ex); s_log.log(Level.SEVERE, "get", ex);
} }
try finally {
{ DB.close(rs, pstmt);
if (pstmt != null) rs = null; pstmt = null;
pstmt.close();
} }
catch (SQLException ex1)
{
}
pstmt = null;
// //
if (retValue == null) if (retValue == null)
{ {