简体   繁体   English

我是否需要next()用于具有一行的ResultSet?

[英]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()。

Yes you need next() 是的,您需要next()

A ResultSet object maintains a cursor pointing to its current row of data. ResultSet对象维护一个游标,该游标指向其当前数据行。 Initially the cursor is positioned before the first row ... 最初,光标位于第一行之前...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的 ResultSet 只用.next() 做一行,但我确实有 3 个 - My ResultSet is only doing one row with .next(), but I do have 3 Java JDBC:查询返回单行时是否需要循环ResultSet? - Java JDBC: Do I need to loop ResultSet when query returns single row? 具有异常的表的DatabaseMetaData.getColumns,而resultSet.next()即ORA-01427:单行子查询返回多行 - DatabaseMetaData.getColumns of a table having exception while resultSet.next() i.e ORA-01427: single-row subquery returns more than one row 避免跳过一行by ResultSet的next()方法 - Avoiding skipping a row By next() Method of ResultSet ResultSet.next()行计数器无法计数 - ResultSet.next() row counter fails to count 一个ResultSet / ResultSet.next()中的多个语句返回false - Multiple Statements in one ResultSet / ResultSet.next() returning false 我想将标签和文本字段彼此对齐,并将所有按钮排成一行; 我该怎么做? - I want to align labels and textfields next to one other and all the buttons in a single row; how can i do it? resultSet.next()做什么 - What does resultSet.next() do resultSet.updateRow()现在如何获取新行的行/位置光标? - resultSet.updateRow() now how do i get the row/position curser at new row? 如果我仅使用SQLite返回一行,是否需要循环? (Android开发人员) - Do I need a loop if I am only returning one row using SQLite? (Android Dev)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM