Why do I see NotUpdatable when I invoke ResultSet.refreshRow()?(为什么我在调用 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
我看到以下异常:
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.
我想知道这个异常,因为如果阅读 refreshRow
方法 javadoc 我们可以找到以下内容:
I wondered this exception because if read refreshRow
method javadoc we can find following:
refreshRow 方法为应用程序提供了一种显式方法告诉 JDBC 驱动程序从数据库中重新获取一行
The refreshRow method provides a way for an application to explicitly tell the JDBC driver to refetch a row(s) from the database
因此如下方向:database -->结果集
我有以下理解:
可更新是使用以下方向的可能性:
updatable is possibility to use following direction:
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 与 Database 混淆了,
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,不是Database,类似
- ResultSet.CONCUR_UPDATABLE,表示可更新的ResultSet,而不是Database.
方法 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么我在调用 ResultSet.refreshRow() 时会看到 NotUpdatable?


基础教程推荐
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01