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

This commit is contained in:
Heng Sin Low 2008-02-14 23:03:38 +00:00
parent cd0d76a388
commit 9e328e0500
1 changed files with 16 additions and 28 deletions

View File

@ -90,30 +90,22 @@ public class MUser extends X_AD_User
+ " AND EXISTS (SELECT * FROM AD_User_Roles ur " + " AND EXISTS (SELECT * FROM AD_User_Roles ur "
+ "WHERE ur.AD_User_ID=u.AD_User_ID AND ur.AD_Role_ID=? AND ur.IsActive='Y')"; + "WHERE ur.AD_User_ID=u.AD_User_ID AND ur.AD_Role_ID=? AND ur.IsActive='Y')";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, null); pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, role.getAD_Role_ID()); pstmt.setInt (1, role.getAD_Role_ID());
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
list.add(new MUser(role.getCtx(), rs, null)); list.add(new MUser(role.getCtx(), 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 ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
MUser[] retValue = new MUser[list.size ()]; MUser[] retValue = new MUser[list.size ()];
@ -215,20 +207,24 @@ public class MUser extends X_AD_User
String name = "?"; String name = "?";
// Get ID // Get ID
String sql = "SELECT Name FROM AD_User WHERE AD_User_ID=?"; String sql = "SELECT Name FROM AD_User WHERE AD_User_ID=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
PreparedStatement pstmt = DB.prepareStatement(sql, null); pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_User_ID); pstmt.setInt(1, AD_User_ID);
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
name = rs.getString(1); name = rs.getString(1);
rs.close();
pstmt.close();
} }
catch (SQLException e) catch (SQLException e)
{ {
s_log.log(Level.SEVERE, sql, e); s_log.log(Level.SEVERE, sql, e);
} }
finally
{
DB.close(rs, pstmt);
}
return name; return name;
} // getNameOfUser } // getNameOfUser
@ -756,32 +752,24 @@ public class MUser extends X_AD_User
String sql = "SELECT * FROM AD_UserBPAccess WHERE AD_User_ID=? AND IsActive='Y'"; String sql = "SELECT * FROM AD_UserBPAccess WHERE AD_User_ID=? AND IsActive='Y'";
ArrayList<X_AD_UserBPAccess> list = new ArrayList<X_AD_UserBPAccess>(); ArrayList<X_AD_UserBPAccess> list = new ArrayList<X_AD_UserBPAccess>();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, null); pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, getAD_User_ID()); pstmt.setInt (1, getAD_User_ID());
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
list.add (new X_AD_UserBPAccess (getCtx(), rs, null)); list.add (new X_AD_UserBPAccess (getCtx(), rs, null));
} }
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 ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
m_bpAccess = new X_AD_UserBPAccess[list.size ()]; m_bpAccess = new X_AD_UserBPAccess[list.size ()];
list.toArray (m_bpAccess); list.toArray (m_bpAccess);