为什么我在调用 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.
相关文章