I have a 2 ResultSet's generated from the same Statement object.
Code Sample follows:
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
con = DBAccess.getConnection();
stmt = con.createStatement();
rs = stmt.executeQuery(Query1);
// operate on the resultset
rs = stmt.executeQuery(Query2); // Is it legal and do not have side-effects?
// operate on the resultset
// close everythings (Resultset, Statement, Connection)
I checked it to work well. My doubt is will it have any side effects ?
From the javadoc :
By default, only one ResultSet object per Statement object can be open at the same time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects. All execution methods in the Statement interface implicitly close a statment's current ResultSet object if an open one exists.
So yes, you can do it safely. You just can't use your first resultset after you have executed the second query.
There will be only one Resultset object for each and every statement object. So, When you execute another query, internally it will close the existing resultset object and opens a new resultset object. But you cannot access the previous resultset obejct.
There will be no side effects. you can use it as you wish.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With