PreparedStatement stmt = con.prepareStatement(sql.toString());
rs = stmt.executeQuery();
i get one Recordset from database. I have to read the rs, to do that i have
to move the rs.next(),
but somwhere down the road (same rs, rs not out of scope) i need to read the
rs again (ok i could store the data into a list but i need to knoe why...),
if i try to rs.previous() or rs.first() i get invalid cursor state?
Thanks
joeNOSPAM@BEA.com - 11 Jan 2007 15:36 GMT
> PreparedStatement stmt = con.prepareStatement(sql.toString());
> rs = stmt.executeQuery();
[quoted text clipped - 5 lines]
> if i try to rs.previous() or rs.first() i get invalid cursor state?
> Thanks
If you re-execute or close the statement, any result set from it
is automatically closed. Also, by default a result set will usually
be FORWARD_ONLY. Use the other prepareStatement call,
telling it what sort of result set you want.
Joe Weinstein at BEA Systems
Tom Hawtin - 11 Jan 2007 17:46 GMT
> PreparedStatement stmt = con.prepareStatement(sql.toString());
> rs = stmt.executeQuery();
[quoted text clipped - 4 lines]
> rs again (ok i could store the data into a list but i need to knoe why...),
> if i try to rs.previous() or rs.first() i get invalid cursor state?
You need to call ResultSet.next to move to the first record. To read the
same record twice, only call next when you first get the ResultSet.
Tom Hawtin