java - 为什么这不关闭 CallableStatement?
问题描述
HibernateCallableStatement 实现了 AutoCloseable 所以一旦 try/catch 完成就应该关闭它。为什么即使将 CallableStatement 传递给另一个类中的 try with resources 块,连接也会保持打开状态?
protected CallableStatement fetchCallableStatement() throws SQLException {
HibernateCallableStatement hcs = new HibernateCallableStatement(this.getDBPackageStatement().getStatement());
this.cs = hcs.getCallableStatement();
for (Param param : getLoadedPackageStatement().getParams()) {
if (param instanceof In) {
this.cs.setObject(param.getPosition(), param.getValue());
} else {
this.cs.registerOutParameter(param.getPosition(), (int) param.getValue());
}
}
this.cs.execute();
return this.cs;
}
try (CallableStatement cs = this.fetchCallableStatement()) {
//CallableStatement Building...
} catch (SQLException ex) {
Logger.getLogger(CursorFetcher.class.getName()).log(Level.SEVERE, null, ex);
}
解决方案
推荐阅读
- bots - 用于为 Disord 编写机器人的最佳语言是什么?
- git - 检查使用了正确版本的 python 的 git hook 会是什么样子?
- php - 今天和unix时间戳之间的天数差异..
- facebook - 使用 Facebook Audience Network SDK 在应用中投放广告
- java - Java:如何更改使用 Spring Boot yml 配置的 mongodb 端口
- javascript - DynamoDB 中的 ScanFilter 使用 BETWEEN comparisonOperator
- c++ - 如何打印二维字符数组 C++
- c# - C#从数据库中加载对象
- python - 如何检查 DataFrame 中的所有值是否在特定条件内?
- jquery - jQuery ui 手风琴子 css-counter 被覆盖