Solved

Count rows in JDBC ResultSet

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now