I know that if you create an SQL PreparedStatement or ResultSet, you should use .close() on the resource when you're finished with it. If however I'm looping and just recreating the PreparedStatement with each iteration, do I still have to call .close() on it during each iteration, or just when I'm finished?
For example, if i have this:
private Connection con;
private String[] queries;
private PreparedStatement stmt;
...
create connection
fill array queries with 10 queries in it
...
for (int i = 0; i < 10; i++) {
stmt = con.prepareStatement(queries[i], Statement.RETURN_GENERATED_KEYS);
stmt.executeUpdate();
// necessary?
stmt.close()
}
Is it necessary to .close() stmt with each iteration, or should I just do it when loop is complete? Why or why not? Thank you.