对于只有一行的结果集,我需要 next() 吗?

Do I need next() for a ResultSet with one row?

我有以下代码

Statement stmt = SqlHelper.initializeDB();
String query = "SELECT status " + 
                "FROM books " + 
                "WHERE bookId = '" + bookId + "'";
ResultSet rs = stmt.executeQuery(query);
result = rs.getString(1);
rs.close();
SqlHelper.closeConnection();

我需要使用 rs.next() 吗?我确信只会有一行数据,因为 bookId 在 table 中必须是唯一的。但是默认情况下,ResultSet 的光标在第一行之前开始,所以我不确定是否需要 next()。

是的,你需要next()

A ResultSet object maintains a cursor pointing to its current row of data. Initially the cursor is positioned before the first row...