jQuery in Action, 3rd edition
The moose likes JDBC and Relational Databases and the fly likes Count of Records Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Count of Records" Watch "Count of Records" New topic

Count of Records

Sridhar M Swaminathan

Joined: Apr 08, 2002
Posts: 7
Hi All..
Which is the best method to count the number of records retrieved by an SQL??
Is it to navigate through the RecordSet till the end? or is there a better method ?
Pls suggest
Rajendar Goud
Ranch Hand

Joined: Mar 06, 2002
Posts: 220
Hi sridhar,
it depends on ur requirement.To keep a count of the number of records in the middle of the query,
then u can define a integer variable and keep incrementing it after each retreiving each record.
i already posted the code in this forum some time back..
Mahesh Mamani
Ranch Hand

Joined: Jun 25, 2001
Posts: 110
Instead of traversing the whole ResultSet and then getting the count, a simpler option is do get the count of the rows using the statement
select count(*) from <table-name>
Hope It Helps.

Sridhar M Swaminathan

Joined: Apr 08, 2002
Posts: 7
Hi Raj & Mahesh..
I agree. Here's the link: http://aspose.com/file-tools
subject: Count of Records
It's not a secret anymore!