File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes ResultSet.next() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ResultSet.next()" Watch "ResultSet.next()" New topic
Author

ResultSet.next()

Raj Kumar
Ranch Hand

Joined: Sep 19, 2005
Posts: 65
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

Joined: Mar 24, 2004
Posts: 15
Wouldn't rs.isAfterLast(); return true if the ResultSet is empty?
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
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

Joined: Jul 31, 2003
Posts: 263


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 ]

Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ResultSet.next()