Reputation: 477
I have the following code
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();
Do I need to use rs.next()? I am sure there is only going to be one row of data because bookId must be unique in the table. But by default, the cursor of ResultSet starts before the first row so I'm not sure if I need next() or not.
Upvotes: 1
Views: 3450
Reputation: 240870
Yes you need next()
A
ResultSet
object maintains a cursor pointing to its current row of data. Initially the cursor is positioned before the first row...
Upvotes: 6