According to the documentation for getResultSet
in java.sql.Statement
, it says:
Retrieves the current result as a ResultSet object. This method should be called only once per result.
Using some test code, I ran executeQuery()
and several calls to getResultSet()
and observed that the ResultSet
returned pointed to the same object. So I'm guessing it is not returning a different ResultSet
which you would need to close individually. But of course this could be unique to my JDBC drivers.
Looking at the documentation for ResultSet
it says:
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.
This seems like a good reason why it may not be a good idea to call it multiple times as it may lead to some "gotcha" situation. If this was the sole reason, I felt that they could have just said that so I think there might be more to it than just this.
So does anyone know why one shouldn't call getResultSet
more than once per result? This question is what made me curious in the first place.