Solved

Count rows in JDBC ResultSet

Posted on 1998-05-19
1
7,148 Views
Last Modified: 2010-05-18
Is there any method get the count of total number of rows retrieved from the ResultSet?
0
Comment
Question by:kulabhi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 4

Accepted Solution

by:
evijay earned 50 total points
ID: 1221211
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.
Suggested Courses

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question