How to get only the first row from a ResultSet

后端 未结 4 364
南旧
南旧 2021-01-01 12:17

How do I get only the first row from a ResultSet? I know how to iterate through the entire set, but how do I get just the first row?

4条回答
  •  时光说笑
    2021-01-01 13:06

    Don't call resultSet.next(); simply extract the data,

    A ResultSet object maintains a cursor pointing to its current row of data. Initially the cursor is positioned before the first row. The next method moves the cursor to the next row, and because it returns false when there are no more rows in the ResultSet object, it can be used in a while loop to iterate through the result set.

    Alternatively You can also call first()

    Moves the cursor to the first row in this ResultSet object.


    • ResultSet

提交回复
热议问题