Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ResultSet - check if empty or not?

807569Sep 14 2006 — edited Sep 22 2006
Hi,
I've read quite a few posts on ResultSets today, but I can't seem to find a satisfactory answer to what I want.

I'm executing an SQL query, then if the ResultSet has no rows (i.e. it's 'empty') then I want to tell the user that their search has no hits. If there are rows, I want to display them.
The problem that I have is that even if I make my statement scrollable, I can't seem to get back to the first row.
Statement S = C.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs = S.executeQuery ("SELECT * FROM etc, etc, .......);
rs.last ();
int rowCount = rs.getRow ();
rs.first ();
if (rowCount > 0)
{
        //...print out the results
}
else
{
        out.println ("No results found");
}
When I do this, the printed result set is always missing the first row of the results. Is there any other way around this other than reading the ResultSet into an ArrayList and then counting it?

Many thanks,
Graham
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 20 2006
Added on Sep 14 2006
21 comments
4,246 views