posted 22 years ago
I have
out.println("This is the search result.");
before I iterate through the ResultSet rs like so:
while(rs.next())
{ ...
}
But then this line: out.println("This is the search result."); will be executed even when no results are returned. This is certainly not very nice.
Too bad that ResulstSet rs=statement.executeQuery(query) never gets a null value, so says the documentation. This means that I can't do
if(rs != null)
{ out.println("This is the search result.");
}
Even worse, I surely can't put that line inside the while loop, like so:
while(rs.next())
{ out.println("This is the search result.");
.......
}
Actually, the following code works:
if(rs.next())
{ out.println("This is the search result.");
}
But, then I'll always miss one row down in the while loop (because the cursor has been moved down one row in the if statement).
I tried
rs.beforeFirst();
after the if block, hoping to move the cursor back one row. It did not work out right.
Understand my problem? Any smart way to handle this?
Thanks.
Gene