【发布时间】:2017-09-30 07:07:59
【问题描述】:
我有这样的方法:
private static ResultSet select (Connection connection, String query) {
PreparedStatement selectQuery = null;
ResultSet resultSet = null;
try {
selectQuery = connection.prepareStatement(query);
resultSet = selectQuery.executeQuery();
selectQuery.close();
} catch (SQLException e) {
System.out.println(e);
}
return resultSet;
}
问题是当我关闭preparedStatement 时resultSet 总是空的。
如果我用服装preparedStatement //selectQuery.close(); 注释掉这条线,一切都很好。
我在为结果集赋值后关闭它。那为什么它是空的呢?
【问题讨论】:
-
可能是因为它被查询关闭而关闭。您不应该返回 ResultSet,“就地”使用它们并丢弃它们