aspose file tools*
The moose likes JDBC and the fly likes How to get row-count out from the ResultSet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to get row-count out from the ResultSet?" Watch "How to get row-count out from the ResultSet?" New topic
Author

How to get row-count out from the ResultSet?

Jorma Ikonen
Ranch Hand

Joined: Sep 17, 2001
Posts: 49
Hi,
I'm just wondering how I can read the number of rows (records) in DB...
ResultSet res = smnt.executeQuery("SELECT count(*) FROM table_name");
what should I do next? I mean that next may not work:
String count = res.getString("???");
I'm also interested in that what is the "official" way to give an unique ID-number for each record. Do I have to give it, or does the DB-server do the job?
Regards,
Jorma
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Or, if you prefer,About ID numbers: you can actually write a whole article about this. There is no out of the box facility to generate ID codes in SQL, but most databases have their own facilities for the purpose. For example, in Oracle you'd use sequences; in SQL Server you'd use identity columns. If you need compatibility with multiple databases, then you either use an old-fashioned "nextnum" type table, or abstract out the database-specific bits into an interface which is implemented separately for each database (data access frameworks such as Castor usually go this route).
- Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get row-count out from the ResultSet?
 
Similar Threads
Count the Records
Display error when record not found
Resultset row count
the workings of ResultSet.getFetchSize()
Problems Processing Large ResultSet