Solved

Count rows in JDBC ResultSet

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
nextBoolean(double p) for Random class 3 41
javap not working 8 58
pagenation logic how it is working in my code 1 52
Problem to Alipay 10 42
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
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.

809 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