aspose file tools*
The moose likes JDBC and the fly likes Return: Illegal operation on empty result set. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Return: Illegal operation on empty result set." Watch "Return: Illegal operation on empty result set." New topic
Author

Return: Illegal operation on empty result set.

Allen Williams
Ranch Hand

Joined: Sep 04, 2006
Posts: 136
So, how do you tell the result set is empty?

When I execute the following code:

I get the following printout:

Apr 15 22:50:19: dbUtils::dbResultSet2Subscription: rs= com.mysql.jdbc.Resul
tSet@6d3b92
Apr 15 22:50:19: rs is NOT before first
Apr 15 22:50:19: dbUtils::dbResultSet2Subscription: setting new subscription

***** Exception
Apr 15 22:50:19: dbUtils::dbResultSet2Subscription: Illegal operation on emp
ty result set.
*****

So, rs is not null, is not before first, but when I go to get the columns, it throws that exception.

BTW, in this case, the result set is empty.

TIA,
Allen


-------<br />Thanks & regards,<br />anw
Allen Williams
Ranch Hand

Joined: Sep 04, 2006
Posts: 136
The answer: rowset::last() set the cursor on the last row, and returns true if it is a valid row, or false if there are no rows in the result set. Kind of convoluted, setting to last just to see if it's valid, then back to first (or before first) to begin using getNext().
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30957
    
158

Why can't you just call rs.next() to see if it is empty?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Allen Williams
Ranch Hand

Joined: Sep 04, 2006
Posts: 136
Here's the whole story: I'm designing a general purpose function to use rs to populate an object from a database, so the user could pass in an rs that is before first, or they may have already checked to see if there are rows by doing getNext() first. In particular, if they want a row count, for example to dimensionalize an array, the only way I know to do this is to do a getLast then get the row number, then set rs back to the "beginning". A user could be perfectly reasonable in calling the "beginning" beforeFirst or calling it the first row, and I was trying to accommodate both in this function.

Therefore, in this function, beforeFirst could return false because a) there are no rows, or b) because it is positioned on the first row. In the latter case, getNext() returns false if there is only one row.

I don't know what would happen if you got a false beforeFirst, because it was empty, but then set it to beforeFirst to check getNext.

Anyway, I think that rs not having isEmpty() and rowCount() methods is a big deficiency. I kludged up a rowCount method as described above, and I actually used that, but the key to it was going to getLast().

Regards,
anw
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Return: Illegal operation on empty result set.