使用PreparedStatements和ResultSets是否每次使用时都会创建"新数据库实例"?或者,换句话说,如果我使用PreparedStatement和ResultSet,我应该在每次使用后关闭它们还是在完成后关闭它们?
例:
while (...){
p = connection.prepareStatement(...);
r = p.executeQuery();
while (r.next()) {
....
}
}
// We close at the end. Or there are any other p and r still opened...?
p.close();
r.close();
Run Code Online (Sandbox Code Playgroud)
要么
while (...){
p = connection.prepareStatement(...);
r = p.executeQuery();
while (r.next()) {
....
}
p.close();
r.close();
}
Run Code Online (Sandbox Code Playgroud)
注意:当然我会尝试并正确关闭,这只是一个例子.