Solved

Count rows in JDBC ResultSet

Posted on 1998-05-19
1
7,142 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
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

Technology Partners: 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

Suggested Solutions

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

685 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