How to check if resultset has one row or more with JDBC?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You didn’t ask this one, but you may need it:
Normally, we don’t need the row count because we use a WHILE loop to iterate through the result set instead of a FOR loop:
However, in some cases, you might want to window the results, and you need the record count ahead of time to display to the user something like
Row 1 to 10 of 100. You can do a separate query withSELECT COUNT(*)first, to get the record count, but note that the count is only approximate, since rows can be added or removed between the time it takes to execute the two queries.Sample from ResultSet Overview