How can I know when I reach the last record in a table, since JDBC doesn't provide an EOF method?

Yusuf Dönmez

You can use last() method of java.sql.ResultSet, if you make it scrollable.

Joe Sam Shirah adds: You can also use isLast() as you are reading the ResultSet.

One thing to keep in mind, though, is that both methods tell you that you have reached the end of the current ResultSet, not necessarily the end of the table. SQL and RDBMSes make no guarantees about the order of rows, even from sequential SELECTs, unless you specifically use ORDER BY. Even then, that doesn't necessarily tell you the order of data in the table.

If you are really looking for something that tells you the last ( in this case, latest ) data, you probably need something in a key ( or sequence, date/time, etc ) that provides that information on an ORDER BY basis.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact