This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes ResultSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "ResultSet" Watch "ResultSet" New topic


Lakshmi Devi

Joined: Jan 25, 2001
Posts: 2
Which method should i use to find the End of ResultSet while looping through it in JDBC 1.0?
Bill Ross

Joined: Dec 20, 2000
Posts: 4
The method returns a boolean true or false indicating whether it is at the end of the result set or not. Therefore, you can just use a while loop to check your result set. Example:
Assumes a valid Connection (con) object instance...
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
//get some results
int iOne = rs.getInt(1);
int iTwo = rs.getInt(2);
storeOrUseYourResultsSomeWhere(iOne, iTwo);
}catch(SQLException sqle){
System.out.println("SQLException: " + sqle);
if(stmt != null)
if (con != null)
}catch(SQLException sqle){
System.out.println("SQLException closing stmt and con: " + sqle);
Real code would do better logging than using System.out.println but it is good for initial trouble shooting. Sun Java Tutorial has a good beginner to middlin' tutorial on JDBC including a bunch of sample code similar to this. It should get you well on your way.
Lakshmi Devi

Joined: Jan 25, 2001
Posts: 2
I got it worked.
Thank you very much Bill Ross.
wood burning stoves
subject: ResultSet
It's not a secret anymore!