aspose file tools*
The moose likes JDBC 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 Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ResultSet" Watch "ResultSet" New topic
Author

ResultSet

Lakshmi Devi
Greenhorn

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
Greenhorn

Joined: Dec 20, 2000
Posts: 4
The ResultSet.next() 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:
<PRE>
Assumes a valid Connection (con) object instance...
try{
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while(rs.next()){
//get some results
int iOne = rs.getInt(1);
int iTwo = rs.getInt(2);
storeOrUseYourResultsSomeWhere(iOne, iTwo);
}
}catch(SQLException sqle){
System.out.println("SQLException: " + sqle);
finally{
try{
if(stmt != null)
stmt.close();
if (con != null)
con.close;
}catch(SQLException sqle){
System.out.println("SQLException closing stmt and con: " + sqle);
}
}
</PRE>
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.
BillR
Lakshmi Devi
Greenhorn

Joined: Jan 25, 2001
Posts: 2
I got it worked.
Thank you very much Bill Ross.
Lakshmi
 
Consider Paul's rocket mass heater.
 
subject: ResultSet