Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7169
  • Last Modified:

Count rows in JDBC ResultSet

Is there any method get the count of total number of rows retrieved from the ResultSet?
0
kulabhi
Asked:
kulabhi
1 Solution
 
evijayCommented:
There is no direct method to retrieve number of rows from ResultSet since the rows are fetched from database on demand.

The best way to solve this problem, is to maintain count the rows with the simple while loop

             count = 0;
             boolean more = rs.next ();
             while (more) {
                     // do the necessary saving/processing of the row here (since you may not get back this row after you call next
                    // for instance, you may add the row content in a vector

                     count ++;
                     more = rs.next ();
             }

            // now count has number of rows



You can control one thing. You can set the maximum number of rows in the result. by calling Statement.setMaxRows method.


0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now