How to get row count using ResultSet in Java?

前端 未结 13 2104
[愿得一人]
[愿得一人] 2020-11-27 13:05

I\'m trying to create a simple method that receives a ResultSet as a parameter and returns an int that contains the row count of the ResultSet. Is this a valid way of doing

13条回答
  •  北海茫月
    2020-11-27 13:45

    Your function will return the size of a ResultSet, but its cursor will be set after last record, so without rewinding it by calling beforeFirst(), first() or previous() you won't be able to read its rows, and rewinding methods won't work with forward only ResultSet (you'll get the same exception you're getting in your second code fragment).

提交回复
热议问题