This question should be simple and it may annoy , but still I got this doubt about closing of Result Set using Java. It should be done for each statement or result set should be closed only in final?
try {
Class.forName(<driver class>);
con = DriverManager.getConnection(
"IP",
"username",
"password");
for(String dealId : items) {
String sql= "SQL Query";
preparedStatement = con.prepareStatement(sql);
rs = preparedStatement.executeQuery();
while(rs.next()) {
count += rs.getInt("total");
}
// Result should be closed here as the statement got executed?
}
System.out.println(count);
if(items.size() == count) {
dealsBelongToTheParty = true;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
rs.close(); // Or this is right?
preparedStatement.close();
if(!con.isClosed())
con.close();
}