相关疑难解决方法(0)

关闭PreparedStatements

使用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)

注意:当然我会尝试并正确关闭,这只是一个例子.

java database recordset

9
推荐指数
2
解决办法
9611
查看次数

标签 统计

database ×1

java ×1

recordset ×1