本文共 628 字,大约阅读时间需要 2 分钟。
根据
java.sql.Statement中的getFesultSet的
documentation,它说:
Retrieves the current result as a ResultSet object. This method should
be called only once per result.
使用一些测试代码,我运行了executeQuery()和几次调用getResultSet(),并观察到返回的ResultSet指向同一个对象.所以我猜它没有返回一个你需要单独关闭的不同ResultSet.但当然这对我的JDBC驱动程序来说可能是独一无二的.
查看ResultSet的documentation,它说:
A default ResultSet object is not updatable and has a cursor that
moves forward only. Thus, you can iterate through it only once and
only from the first row to the last row.
这似乎是一个很好的理由,为什么多次调用它可能不是一个好主意,因为它可能导致一些“陷阱”情况.如果这是唯一的原因,我觉得他们可能刚刚说过,所以我认为可能还有更多不仅仅是这个.
那么有谁知道为什么每个结果不应该多次调用getResultSet?这个question首先让我好奇.
转载地址:https://blog.csdn.net/weixin_33758343/article/details/114190430 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!