BF [ 1874419 ] JDBC Statement not close in a finally block
ACTION: Done two db.close acts. Please review. TESTS: Tested in Eclipse debug to confirm methods called without incident. Compiled deployed on desktop, looks OK. Committing for higher level review.
This commit is contained in:
parent
84b3b5b135
commit
4ffe1affbd
|
@ -257,6 +257,7 @@ public class Login
|
||||||
sql.append(" AND (u.Password=? OR u.Password=?)"); // #2/3
|
sql.append(" AND (u.Password=? OR u.Password=?)"); // #2/3
|
||||||
sql.append(" ORDER BY r.Name");
|
sql.append(" ORDER BY r.Name");
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement(sql.toString(), null);
|
pstmt = DB.prepareStatement(sql.toString(), null);
|
||||||
|
@ -267,7 +268,7 @@ public class Login
|
||||||
pstmt.setString(3, SecureEngine.encrypt(app_pwd));
|
pstmt.setString(3, SecureEngine.encrypt(app_pwd));
|
||||||
}
|
}
|
||||||
// execute a query
|
// execute a query
|
||||||
ResultSet rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
|
|
||||||
if (!rs.next()) // no record found
|
if (!rs.next()) // no record found
|
||||||
if (force)
|
if (force)
|
||||||
|
@ -324,10 +325,6 @@ public class Login
|
||||||
list.add(p);
|
list.add(p);
|
||||||
}
|
}
|
||||||
while (rs.next());
|
while (rs.next());
|
||||||
|
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
pstmt = null;
|
|
||||||
//
|
//
|
||||||
retValue = new KeyNamePair[list.size()];
|
retValue = new KeyNamePair[list.size()];
|
||||||
list.toArray(retValue);
|
list.toArray(retValue);
|
||||||
|
@ -340,15 +337,10 @@ public class Login
|
||||||
retValue = null;
|
retValue = null;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
try
|
finally
|
||||||
{
|
{
|
||||||
if (pstmt != null)
|
DB.close(rs, pstmt);
|
||||||
pstmt.close();
|
rs = null; pstmt = null;
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
long ms = System.currentTimeMillis () - start;
|
long ms = System.currentTimeMillis () - start;
|
||||||
return retValue;
|
return retValue;
|
||||||
|
@ -379,12 +371,13 @@ public class Login
|
||||||
+ " AND r.IsActive='Y' AND c.IsActive='Y'";
|
+ " AND r.IsActive='Y' AND c.IsActive='Y'";
|
||||||
|
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
// get Role details
|
// get Role details
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement(sql, null);
|
pstmt = DB.prepareStatement(sql, null);
|
||||||
pstmt.setInt(1, role.getKey());
|
pstmt.setInt(1, role.getKey());
|
||||||
ResultSet rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
|
|
||||||
if (!rs.next())
|
if (!rs.next())
|
||||||
{
|
{
|
||||||
|
@ -437,15 +430,10 @@ public class Login
|
||||||
log.log(Level.SEVERE, sql, ex);
|
log.log(Level.SEVERE, sql, ex);
|
||||||
retValue = null;
|
retValue = null;
|
||||||
}
|
}
|
||||||
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;
|
||||||
} // getClients
|
} // getClients
|
||||||
|
@ -488,13 +476,14 @@ public class Login
|
||||||
//
|
//
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
MRole role = null;
|
MRole role = null;
|
||||||
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement(sql, null);
|
pstmt = DB.prepareStatement(sql, null);
|
||||||
pstmt.setInt(1, AD_Role_ID);
|
pstmt.setInt(1, AD_Role_ID);
|
||||||
pstmt.setInt(2, client.getKey());
|
pstmt.setInt(2, client.getKey());
|
||||||
pstmt.setInt(3, AD_User_ID);
|
pstmt.setInt(3, AD_User_ID);
|
||||||
ResultSet rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
// load Orgs
|
// load Orgs
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
|
@ -514,9 +503,6 @@ public class Login
|
||||||
list.add(p);
|
list.add(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
pstmt = null;
|
|
||||||
//
|
//
|
||||||
retValue = new KeyNamePair[list.size()];
|
retValue = new KeyNamePair[list.size()];
|
||||||
list.toArray(retValue);
|
list.toArray(retValue);
|
||||||
|
@ -530,15 +516,10 @@ public class Login
|
||||||
log.log(Level.SEVERE, sql, ex);
|
log.log(Level.SEVERE, sql, ex);
|
||||||
retValue = null;
|
retValue = null;
|
||||||
}
|
}
|
||||||
try
|
finally
|
||||||
{
|
{
|
||||||
if (pstmt != null)
|
DB.close(rs, pstmt);
|
||||||
pstmt.close();
|
rs = null; pstmt = null;
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
// No Orgs
|
// No Orgs
|
||||||
if (retValue == null || retValue.length == 0)
|
if (retValue == null || retValue.length == 0)
|
||||||
|
@ -586,12 +567,13 @@ public class Login
|
||||||
+ " WHERE AD_Tree_ID=? AND Parent_ID=? AND IsActive='Y') "
|
+ " WHERE AD_Tree_ID=? AND Parent_ID=? AND IsActive='Y') "
|
||||||
+ "ORDER BY Name";
|
+ "ORDER BY Name";
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement (sql, null);
|
pstmt = DB.prepareStatement (sql, null);
|
||||||
pstmt.setInt (1, tree.getAD_Tree_ID());
|
pstmt.setInt (1, tree.getAD_Tree_ID());
|
||||||
pstmt.setInt (2, Summary_Org_ID);
|
pstmt.setInt (2, Summary_Org_ID);
|
||||||
ResultSet rs = pstmt.executeQuery ();
|
rs = pstmt.executeQuery ();
|
||||||
while (rs.next ())
|
while (rs.next ())
|
||||||
{
|
{
|
||||||
int AD_Client_ID = rs.getInt(1);
|
int AD_Client_ID = rs.getInt(1);
|
||||||
|
@ -608,23 +590,15 @@ public class Login
|
||||||
list.add(p);
|
list.add(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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 ();
|
rs = null; pstmt = null;
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
} // getOrgAddSummary
|
} // getOrgAddSummary
|
||||||
|
|
||||||
|
@ -647,11 +621,12 @@ public class Login
|
||||||
+ "WHERE AD_Org_ID=? AND IsActive='Y' "
|
+ "WHERE AD_Org_ID=? AND IsActive='Y' "
|
||||||
+ "ORDER BY Name";
|
+ "ORDER BY Name";
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement(sql, null);
|
pstmt = DB.prepareStatement(sql, null);
|
||||||
pstmt.setInt(1, org.getKey());
|
pstmt.setInt(1, org.getKey());
|
||||||
ResultSet rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
|
|
||||||
if (!rs.next())
|
if (!rs.next())
|
||||||
{
|
{
|
||||||
|
@ -685,15 +660,10 @@ public class Login
|
||||||
log.log(Level.SEVERE, "getWarehouses", ex);
|
log.log(Level.SEVERE, "getWarehouses", ex);
|
||||||
retValue = null;
|
retValue = null;
|
||||||
}
|
}
|
||||||
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;
|
||||||
} // getWarehouses
|
} // getWarehouses
|
||||||
|
@ -802,12 +772,13 @@ public class Login
|
||||||
+ "WHERE a.C_AcctSchema_ID=c.C_AcctSchema1_ID "
|
+ "WHERE a.C_AcctSchema_ID=c.C_AcctSchema1_ID "
|
||||||
+ "AND c.AD_Client_ID=?";
|
+ "AND c.AD_Client_ID=?";
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int C_AcctSchema_ID = 0;
|
int C_AcctSchema_ID = 0;
|
||||||
pstmt = DB.prepareStatement(sql, null);
|
pstmt = DB.prepareStatement(sql, null);
|
||||||
pstmt.setInt(1, AD_Client_ID);
|
pstmt.setInt(1, AD_Client_ID);
|
||||||
ResultSet rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
|
|
||||||
if (!rs.next())
|
if (!rs.next())
|
||||||
{
|
{
|
||||||
|
@ -891,15 +862,10 @@ public class Login
|
||||||
{
|
{
|
||||||
log.log(Level.SEVERE, "loadPreferences", e);
|
log.log(Level.SEVERE, "loadPreferences", e);
|
||||||
}
|
}
|
||||||
try
|
finally
|
||||||
{
|
{
|
||||||
if (pstmt != null)
|
DB.close(rs, pstmt);
|
||||||
pstmt.close();
|
rs = null; pstmt = null;
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
Ini.saveProperties(Ini.isClient());
|
Ini.saveProperties(Ini.isClient());
|
||||||
|
@ -928,10 +894,11 @@ public class Login
|
||||||
sql = MRole.getDefault(m_ctx, false).addAccessSQL(sql,
|
sql = MRole.getDefault(m_ctx, false).addAccessSQL(sql,
|
||||||
TableName, MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
|
TableName, MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement(sql, null);
|
pstmt = DB.prepareStatement(sql, null);
|
||||||
ResultSet rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
if (rs.next())
|
if (rs.next())
|
||||||
value = rs.getString(1);
|
value = rs.getString(1);
|
||||||
rs.close();
|
rs.close();
|
||||||
|
@ -943,15 +910,10 @@ public class Login
|
||||||
log.log(Level.SEVERE, TableName + " (" + sql + ")", e);
|
log.log(Level.SEVERE, TableName + " (" + sql + ")", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try
|
finally
|
||||||
{
|
{
|
||||||
if (pstmt != null)
|
DB.close(rs, pstmt);
|
||||||
pstmt.close();
|
rs = null; pstmt = null;
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
// Set Context Value
|
// Set Context Value
|
||||||
if (value != null && value.length() != 0)
|
if (value != null && value.length() != 0)
|
||||||
|
|
Loading…
Reference in New Issue