【发布时间】:2015-12-16 08:49:45
【问题描述】:
我有一个代码,我使用结果集连接到 db,然后在获得必要的值后在 finally 块中关闭连接。
但由于某种原因,查询仍在运行,连接池未释放。 有人可以在这里帮忙吗?
try {
rsU = dbAccess.query(FasoCommon.sqlUpdatable, params, true);
if (rsU.next()) {
updatable = rsU.getString("UpdatableFields");
logger.info("UpdatableFields:: "+updatable);
}
}
finally {
close(rsU, null, null);
}
private void close(ResultSet rs, Statement stmt, Connection conn) {
if (rs != null) {
try {
rs.close();
rs=null;
//logger().info("ResultSet Closed : " + rs);
} catch (SQLException e) {
//logger().error("The result set cannot be closed.", e);
}
}
if (stmt != null) {
try {
stmt.close();
stmt=null;
//logger().info("Statement Closed : " + stmt);
} catch (SQLException e) {
//logger().error("The statement cannot be closed.", e);
}
}
if (conn != null) {
try {
conn.close();
conn=null;
//logger().info("Data Source Connection Closed : " + conn);
} catch (SQLException e) {
}
}
}
【问题讨论】:
-
您可以在下面查看我的答案,并纠正您在此上下文中使用关键字结果集的问题。 ResultSet 是在执行查询时填充的对象。希望这可以帮助。检查此链接以了解更多信息:tutorials.jenkov.com/jdbc/resultset.html
标签: java sql database datasource resultset