deltanovember
deltanovember

Reputation: 44051

Is it possible to tell if a java ResultSet is empty without affecting the record?

I do not want to use next() since if the ResultSet is not empty, I do not want the cursor to be advanced. Is there some sort of peek() method or equivalent that will return false if the ResultSet is empty and true otherwise without affecting the record?

Edit:

I cannot call beforeFirst because I get the following

Operation requires a scrollable ResultSet, but this ResultSet is FORWARD_ONLY

I need FORWARD_ONLY because I'm using postgreSQL cursors

Upvotes: 3

Views: 2711

Answers (3)

Ali
Ali

Reputation: 12684

isBeforeFirst() returns true if the cursor is before the first row or false if it is in any other position or the resultset is empty.

Check out the Java API for ResultSet for isBeforeFirst()

Upvotes: 2

ngesh
ngesh

Reputation: 13501

   getFetchSize()

based on the size returned you can proceed...

Upvotes: -2

Sanjay T. Sharma
Sanjay T. Sharma

Reputation: 23208

You can invoke the first() method to check if you have results in the ResultSet. If first() returns true, you can then call beforeFirst() to reset the ResultSet cursor position.

Upvotes: 1

Related Questions