I am using jdbc to connect to oracle 10g. I can connect to the db and get the resultset. I have 2 rows in my table. I am able to use resultsetmetadata on the resultset.
But, when I try to retrieve the values from the resultset, I get the following exception
"java.sql.SQLException: Result set is in an invalid state. May be before the first row or after the last row."
When I try to use various methods in the resultset for checking, I find isAfterLast and isFirst both methods returning true. I am not able to understand, where the cursor points to now. I am using scrollable resultset. My resultset is not null.
You'll notice that the API documentation for the executeQuery() method of Statement says:
a ResultSet object that contains the data produced by the given query; never null
So don't waste your time testing to see if it's null. But even so, if you have a ResultSet object (which is what the != null test tells you that you do) there's no reason why it shouldn't contain zero rows. Don't confuse "null" with "empty".
Joined: Oct 08, 2006
Kalai Selvi wrote:If the resultset doesnot contain any rows, then what would it return if we check
if (rs != null)
In my case, this returns true. Is it possible, this returns true even if there are no rows in my resultset?
As said, this is totally wrong. The obtained ResultSet is never ever null.
Just check if ResultSet#next() returns true. You normally do that in an if or a while statement.
subject: Problem with rs.isAfterLast() and rs.isFirst()