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

This commit is contained in:
teo_sarca 2008-02-03 10:20:36 +00:00
parent fba218d872
commit 4bb15e12d2
1 changed files with 8 additions and 20 deletions

View File

@ -103,6 +103,7 @@ public class Query {
} }
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, trxName); pstmt = DB.prepareStatement (sql, trxName);
@ -113,27 +114,20 @@ public class Query {
pstmt.setObject(i+1, parameters[i]); pstmt.setObject(i+1, parameters[i]);
} }
} }
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
PO po = table.getPO(rs, trxName); PO po = table.getPO(rs, trxName);
list.add(po); list.add(po);
} }
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (SQLException e) catch (SQLException e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
throw e; throw e;
} finally { } finally {
try { DB.close(rs, pstmt);
if (pstmt != null) rs = null; pstmt = null;
pstmt.close ();
}
catch (Exception e){}
pstmt = null;
} }
return list; return list;
} }
@ -164,6 +158,7 @@ public class Query {
sql = role.addAccessSQL(sql, table.getTableName(), true, false); sql = role.addAccessSQL(sql, table.getTableName(), true, false);
} }
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
List<Object[]> idList = new ArrayList<Object[]>(); List<Object[]> idList = new ArrayList<Object[]>();
try try
{ {
@ -175,7 +170,7 @@ public class Query {
pstmt.setObject(i+1, parameters[i]); pstmt.setObject(i+1, parameters[i]);
} }
} }
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
Object[] ids = new Object[keys.length]; Object[] ids = new Object[keys.length];
@ -184,21 +179,14 @@ public class Query {
} }
idList.add(ids); idList.add(ids);
} }
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (SQLException e) catch (SQLException e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
throw e; throw e;
} finally { } finally {
try { DB.close(rs, pstmt);
if (pstmt != null) rs = null; pstmt = null;
pstmt.close ();
}
catch (Exception e) {}
pstmt = null;
} }
return new POIterator(table, idList, trxName); return new POIterator(table, idList, trxName);
} }