stephan_zehnder
asked on
How to check if a ResultSet contains no data
How can I check if a ResultSet contains data or not?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
if ( !rs.next() ) {
// no Data
}
isn't there the possibility, that the cursor is on the first one. so even if !rs.next() returns true there could be one row?
i use it for a unit test, so no need to process data, because there shouldn't be.
maybe this
((!rs.next())&&(!rs.isFirs t())) ??
// no Data
}
isn't there the possibility, that the cursor is on the first one. so even if !rs.next() returns true there could be one row?
i use it for a unit test, so no need to process data, because there shouldn't be.
maybe this
((!rs.next())&&(!rs.isFirs
>> isn't there the possibility, that the cursor is on the first one. so even if !rs.next() returns true there could be one row?
No. I quote from the API docs:
A ResultSet object maintains a cursor pointing to its current row of data.
Initially the cursor is positioned before the first row.
The next method moves the cursor to the next row,
and because it returns false when there are no more rows in the ResultSet object,
it can be used in a while loop to iterate through the result set.
No. I quote from the API docs:
A ResultSet object maintains a cursor pointing to its current row of data.
Initially the cursor is positioned before the first row.
The next method moves the cursor to the next row,
and because it returns false when there are no more rows in the ResultSet object,
it can be used in a while loop to iterate through the result set.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for accepting.
For my interest: Could you tell me what you missed in my comment for not awarding it with an A?
For your interest: You can always ask for more explanation if you're not completely satisfied with a comment.
For my interest: Could you tell me what you missed in my comment for not awarding it with an A?
For your interest: You can always ask for more explanation if you're not completely satisfied with a comment.
I think the answer I gave was quite correct, isn't it?
ResultSet rs = preparedStatement.executeQ
while ( rs.next() ) {
// process the result set data
}