- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在我们的代码库上运行了 findbugs,它指出还有两个语句仍需要关闭。在这部分代码中,我们运行:
preparedStatement = connection.prepareStatement(query);
对于 3 个不同的查询,重用 preparedStatement。在 finally block 中,我们确实关闭了资源:
finally{
try{
if (resultSet != null)
resultSet.close();
} catch (Exception e) {
exceptionHandler.ignore(e);
}
try {
if (preparedStatement != null)
preparedStatement.close();
} catch(Exception e) {
exceptionHandler.ignore(e);
}
是否应该在下一个connection.prepareStatement(query)之前关闭语句;还是这个 findbugs 很谨慎?
最佳答案
是的,在执行下一个 connection.prepareStatement 之前必须关闭该语句。否则,您将丢失对未关闭的前一个(也称为泄漏语句)的引用。在每个语句 use 周围包装一个 try {} finally {},在 finally 中将其关闭。
关于java - 重用 PreparedStatement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1018123/
我有一个简单的问题。我的代码中有一些内存泄漏,因为我认为这是因为 PreparedStatement 和 ResultSet 我想知道释放资源及其内存的最佳、安全和正确的方法是什么。 Prepared
package jdbcDemo; import java.sql.*; public class PreparedStatement { public static void mai
服务器端和客户端上的语句缓存是通过 PreparedStatement 的字符串呈现严格缓存还是其他什么?换句话说,如果两个不同的 PreparedStatement 是通过不同的方式创建的,但最终具
我对 C++ Mysql 连接器有“一点”问题。我想使用 PreparedStatement。我尝试了文档中的示例 http://dev.mysql.com/doc/refman/5.1/en/con
我已经将 JAVA 应用程序与 MySql 连接起来。当我编写 PreparedStatement ps = null ;然后显示导入包的两个选项。两个建议的包是:com.mysql.jdbc.Pre
PreparedStatement setString 取一个“null”(就像 String a = "null"),在 .addBatch 之后它被转换成一个普通的 null(就像 String
我正在使用 PreparedStatement 的 setString 方法在 sql 查询中设置开始日期和结束日期的值。 String sql = "..... " AND tableA.time
这个问题已经有答案了: Using Prepared Statements to set Table Name (8 个回答) 已关闭 5 年前。 我正在尝试使用准备好的语句创建一个新表,但收到错误
使用 SQL 的最佳解决方法是什么 IN具有 java.sql.PreparedStatement 实例的子句,由于 SQL 注入(inject)攻击安全问题,不支持多个值:1 ?占位符代表一个值,而
我正在开发一个使用PreparedStatement的java应用程序。 SELECT FIELD1, FIELD2 FROM MYTABLE WHERE (FIELD1='firstFieldVal
我正在使用PreparedStatements写入数据库,有时我会在日志中看到以下内容: 2015-02-02 15:44:14,601 WARN SQL Warning Code: 1292,
query = "SELECT * FROM POST_COMMENT WHERE Post_date_time= ? AND Post_User= !;"; query = query.r
有没有一种方法可以在 php 准备好的语句中设置字段名称,而不是仅仅设置那里的值,例如, $stmt = $mysqli->prepare("UPDATE movies SET filmName =
我对“同时使用 Java 和 SQL”这整个事情还很陌生,我似乎找不到解决这个问题的方法。我通过 Workbench 在服务器上创建了一个数据库,现在我正在使用它的 Netbeans 创建一个简单的应
我对这样的准备好的语句有疑问: select ... from ... where xy = ? and foo = ? and bla = ? 我可以为每个索引设置一个字符串吗?否则我不得不做 pr
我有一个多线程代码的工作版本,但是我对我的 PreparedStatement-wrapper 类是非线程安全的感到不满意。所以我决定在 ThreadLocal 中生成 PreparedStateme
当使用 JDBC 的 PreparedStatements 查询 Oracle 时,请考虑: String qry1 = "SELECT col1 FROM table1 WHERE rownum=?
使用 SQL 的最佳解决方法是什么 IN具有 java.sql.PreparedStatement 实例的子句,由于 SQL 注入(inject)攻击安全问题,不支持多个值:1 ?占位符代表一个值,而
使用 SQL 的最佳解决方法是什么 IN具有 java.sql.PreparedStatement 实例的子句,由于 SQL 注入(inject)攻击安全问题,不支持多个值:1 ?占位符代表一个值,而
使用 SQL 的最佳解决方法是什么 IN具有 java.sql.PreparedStatement 实例的子句,由于 SQL 注入(inject)攻击安全问题,不支持多个值:1 ?占位符代表一个值,而
我是一名优秀的程序员,十分优秀!