Saturday, June 9, 2007

How to get count of rows there are in a Result Set?

There are three ways:
- Do a query like "select count(*) from ... "
-If you need all the data, count the rows as you loop through the data:

int count = 0;
while (rs.next()) {
  count++;
  // anything that you like to do here
}
-If you have a JDBC 3 driver, you can call rs.afterLast() to move to the end and then rs.getRow() to get the row number. This Result Set MUST have a scrollable cursor. Either ScrollSensitive or Insensitive but it does not  work with a Forward Only cursor

0 comments :

 

Disclaimer
Interview Questions On Java,Java EE Copyright © 2016. Reads: best tracker