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 do you get the complete count of records?

 
Sam Moran
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a previous post someone suggested the following:
rs.last();
int numRows = rs.getRow();
Unfortunetly this yacks when I run it. It compiles fine, but I get a message about forward movement only?!?!?
Any ideas, bulah?
 
Jeff Grant
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thinking back... I was sure that there was some sort of ResultSet.getCount() function. HOWERVER, I came to find out I was mistaken when I took a browse of java.sun.com to see that there is not!
Taking that into consideration, and thinking a little more, I believe that the rare case I wanted the count of the rows, I would simply open the DB connection and send a simple count query to the database.
Example

However, if you needed to have the count to then work with the result set using that number (for loop constraints), then simply open the DB connection, send the count query, pull out the single row returned with ResultSet.getInt(1) then send the actual query you want to work with.
Example

Of course, if you don't need to work with the total with the actual query itself, you could just toss a counter in your
function and you'd get your total at the end anyways.
Oh well, hope one of these solutions works for you. I bet you've already thought of the last example though.
 
Jeff Grant
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way... looking back at the original post, here is another idea I had.
Perhaps ResultSet.last() sends it to the last one in the list which might be NULL? Maybe try ResultSet.last(); and then ResultSet.previous(); THEN ResultSet.getRow(); just for the heck of it. Though, you might have problems if there is only 1 or 0 rows returned.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic