gpt4 book ai didi

java - 关闭 preparedStatement 时结果集为空

转载 作者:行者123 更新时间:2023-11-30 06:48:48 24 4
gpt4 key购买 nike

我有这样一个方法:

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 总是空的。如果我用 clothing preparedStatement //selectQuery.close(); 注释掉那一行,一切都很好。我在 为结果集赋值后关闭它。那为什么它是空的?

最佳答案

ResultSet 与执行的Statement 相关联。关闭语句和结果集,其中的所有数据都被清除。

您需要在关闭语句之前处理结果集,因此您的方法将不起作用。

关于java - 关闭 preparedStatement 时结果集为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43743308/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com