Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / January 2007

Tip: Looking for answers? Try searching our database.

PreparedStatement and cursor on rs

Thread view: 
polilop - 11 Jan 2007 08:21 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.