Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get row-count out from the ResultSet?

 
Jorma Ikonen
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic