*BF [ 1874419 ] JDBC Statement not close in a finally block - fixed in 2 spots

*Organize imports
This commit is contained in:
Redhuan D. Oon 2008-02-09 10:12:24 +00:00
parent 6b2e33bb3b
commit 28c5fb4621
1 changed files with 19 additions and 28 deletions

View File

@ -16,10 +16,15 @@
*****************************************************************************/ *****************************************************************************/
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.Properties;
import java.util.logging.Level;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
/** /**
* Account Object Entity to maintain all segment values. * Account Object Entity to maintain all segment values.
@ -230,31 +235,24 @@ public class MAccount extends X_C_ValidCombination
MAccount retValue = null; MAccount retValue = null;
String sql = "SELECT * FROM C_ValidCombination WHERE C_AcctSchema_ID=? AND Alias=?"; String sql = "SELECT * FROM C_ValidCombination WHERE C_AcctSchema_ID=? AND Alias=?";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, null); pstmt = DB.prepareStatement (sql, null);
pstmt.setInt(1, C_AcctSchema_ID); pstmt.setInt(1, C_AcctSchema_ID);
pstmt.setString (2, alias); pstmt.setString (2, alias);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
if (rs.next ()) if (rs.next ())
retValue = new MAccount (ctx, rs, null); retValue = new MAccount (ctx, rs, null);
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;
} // get } // get
@ -377,10 +375,11 @@ public class MAccount extends X_C_ValidCombination
int count = 0; int count = 0;
int errors = 0; int errors = 0;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, trxName); pstmt = DB.prepareStatement (sql, trxName);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
MAccount account = new MAccount (ctx, rs, trxName); MAccount account = new MAccount (ctx, rs, trxName);
@ -390,23 +389,15 @@ public class MAccount extends X_C_ValidCombination
else else
errors++; errors++;
} }
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;
} }
s_log.info(where + " #" + count + ", Errors=" + errors); s_log.info(where + " #" + count + ", Errors=" + errors);
} // updateValueDescription } // updateValueDescription