Why do I see NotUpdatable when I invoke ResultSet.refreshRow()?

主宰稳场 提交于 2019-12-04 04:44:12

问题


When I invoke following rows:

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

I see following exception:

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.

I wondered this exception because if read refreshRow method 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

Thus following direction: database --> ResultSet

I have following understanding:

updatable is possibility to use following direction:

ResultSet --> database

Thus I don't understand cause of problem.

please clarify.


回答1:


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

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.\

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

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, means read only ResultSet, not Database, similarly
  • ResultSet.CONCUR_UPDATABLE, means updatable ResultSet, not Database.

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



来源:https://stackoverflow.com/questions/25582698/why-do-i-see-notupdatable-when-i-invoke-resultset-refreshrow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!