java - Using a ResultSet after executing two different queries with statement.executeQuery() -
this question has answer here:
given code below:
//connection stuff resultset rs = statement.executequery(query1); statement.executequery(query2); while(rs.next){ //code }
is result set rs
still valid though second statement has been executed?
i know when close statement result set isn't valid longer, here code executing query , not storing in result set.
presuming statement
statement
, javadoc:
by default, 1 resultset object per statement object can open @ same time. therefore, if reading of 1 resultset object interleaved reading of another, each must have been generated different statement objects. execution methods in statement interface implicitly close statment's current resultset object if open 1 exists.
the posted code unsafe - second call executequery
return new resultset
, , given 1 can open @ time rs
not valid.
Comments
Post a Comment