[英]Do I need next() for a ResultSet with one row?
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()? 我需要使用rs.next()吗? I am sure there is only going to be one row of data because bookId must be unique in the table.
我敢肯定只有一行数据,因为bookId在表中必须是唯一的。 But by default, the cursor of ResultSet starts before the first row so I'm not sure if I need next() or not.
但是默认情况下,ResultSet的游标从第一行开始,因此我不确定是否需要next()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.