Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ResultSet.next()

 
Raj Kumar
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
is there a generic way to identify if a resultset is empty because if i'am going to use ResultSet.next() to an empty resutset it throws an exception.

Let me know if there is any Generic way to get this information from the resultset.

Thanks in advance.
 
Jerry Olsson
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouldn't rs.isAfterLast(); return true if the ResultSet is empty?
 
Maximilian Xavier Stocker
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vijay vinayagam:
Hi ,
is there a generic way to identify if a resultset is empty because if i'am going to use ResultSet.next() to an empty resutset it throws an exception.


No it does not throw an exception. It returns false. If it throws an exception that is because something else is wrong but it has nothing to do with next.
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


When a resultset is returned, the cursor is positioned before the first record. next() returns true if the next record was retrieved sucessfully. If the recordset is empty, your first call to next() will return false. next() only throws an exception if there is a database error, and an empty result set IS NOT a database error.

Perhaps, you are getting an exception because your result set variable is null or does not point to a resultset object?

Cheers,
[ October 06, 2005: Message edited by: Tom Blough ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic