为什么我调用ResultSet.refreshRow()时看到NotUpdatable? [英] Why do I see NotUpdatable when I invoke ResultSet.refreshRow()?

查看:1172
本文介绍了为什么我调用ResultSet.refreshRow()时看到NotUpdatable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我调用以下行时:

Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet resultSet = statement.executeQuery("select * from user");
resultSet.next();
resultSet.refreshRow();//exception throws here

我看到以下异常: / p>

I see following exception:


com.mysql.jdbc.NotUpdatable:结果集不可更新。此结果集
必须来自一个创建的语句结果集类型为
ResultSet.CONCUR_UPDATABLE,查询必须只选择一个表,可以
不使用函数,并且必须从该表中选择所有主键。
有关更多细节,请参阅JDBC 2.1 API规范第5.6节。此
结果集必须来自使用结果创建的语句
ResultSet.CONCUR_UPDATABLE的集合类型,查询必须选择只有一个
表,不能使用函数,必须从
表中选择所有主键。有关
的详细信息,请参阅JDBC 2.1 API规范第5.6节。

com.mysql.jdbc.NotUpdatable: Result Set not updatable.This result set must come from a statement that was created with a result set type of ResultSet.CONCUR_UPDATABLE, the query must select only one table, can not use functions and must select all primary keys from that table. See the JDBC 2.1 API Specification, section 5.6 for more details.This result set must come from a statement that was created with a result set type of ResultSet.CONCUR_UPDATABLE, the query must select only one table, can not use functions and must select all primary keys from that table. See the JDBC 2.1 API Specification, section 5.6 for more details.

我想知道这个异常, $ c> refreshRow 方法javadoc我们可以找到以下内容:

I wondered this exception because if read refreshRowmethod javadoc we can find following:

The refreshRow method provides a way for an application to explicitly tell the JDBC driver to refetch a row(s) from the database

database - > ResultSet

我有以下理解:

ResultSet --> database

因此我不明白问题的原因。

Thus I don't understand cause of problem.

请澄清。

推荐答案

使用时, ResultSet.CONCUR_READ_ONLY ,您会得到一个例外,

When you are using, ResultSet.CONCUR_READ_ONLY, you are getting an exception, that


com.mysql.jdbc.NotUpdatable:结果集不可更新。此结果集
必须来自使用结果集类型
ResultSet.CONCUR_UPDATABLE创建的语句,查询必须只选择一个表,可以
不使用函数,并且必须从中选择所有主键表。
有关更多详细信息,请参阅JDBC 2.1 API规范第5.6节。\

com.mysql.jdbc.NotUpdatable: Result Set not updatable.This result set must come from a statement that was created with a result set type of ResultSet.CONCUR_UPDATABLE, the query must select only one table, can not use functions and must select all primary keys from that table. See the JDBC 2.1 API Specification, section 5.6 for more details.\

因此,更改 ResultSet.CONCUR_READ_ONLY ResultSet.CONCUR_UPDATABLE ,解决了您的问题。正确?

So, changing ResultSet.CONCUR_READ_ONLY to ResultSet.CONCUR_UPDATABLE, solved your problem. Correct?

现在,据我所知,你不想这样做。我对吗?如果是的话,那么我认为你会把ResultSet和数据库混淆起来,

Now, as I understand, you don't want to do that. Am I right? If yes, then I think you are confusing ResultSet with Database,


  • ResultSet.CONCUR_READ_ONLY表示只读ResultSet, li>
  • ResultSet.CONCUR_UPDATABLE,表示可更新的ResultSet,而不是数据库。

方法 resultSet.refreshRow(),假设更新 resultSet ,因此它正确地需要可更新 ResultSet 。我希望现在很清楚。

The method, resultSet.refreshRow(), suppose to update the resultSet, hence it rightly requires updatable ResultSet. I hope it's clear now.

这篇关于为什么我调用ResultSet.refreshRow()时看到NotUpdatable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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