ResultSet .next is not called 异常被抛出 [英] ResultSet .next was not called exception is thrown

查看:91
本文介绍了ResultSet .next is not called 异常被抛出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的查询

String sql_query = select name, display_name from parameter where id = (something);

执行此查询后,我检索了 ResultSet,然后尝试更新值 display_name.它不起作用并抛出异常

After executing this query I retrieved the ResultSet, and then I'm trying to update the value display_name. It's not working and throwing an Exception

.next 没有被调用.

.next was not called.

rs = stmt.executeQuery(sql_query);
String displayName = rs.getString(display_name);
displayName = displayName.replace("&lt;", "<");
rs.updateString(display_name,display name);

推荐答案

如果您只想检索一行详细信息,则需要调用 rs.next() 将光标移动到第一行.首先,光标位于第一行之前.如果你想处理多条记录,你可以循环遍历你的结果集,如下所示.next() 方法返回false,因此可用于循环直到结果集结束.

If you just want to retrieve one row details, you need to call rs.next() to move the cursor to first row. To start with, cursor is positioned before the first row. If you want to deal with multiple records, you can loop through your resultset as below. next() method returns false, so it can be used to loop till end of resultset.

while(rs.next()) {
  String displayName = rs.getString(display_name);
  displayName = displayName.replace("&lt;", "<");
  rs.updateString(display_name,display name);
}

这篇关于ResultSet .next is not called 异常被抛出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆