为何出现这个错误:java.sql.SQLException: 对只读结果集的无效操作: updateString;code如下:

bellfeel 2002-05-14 09:44:25
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@team1-server:1521:hims","eharbor","eharbor");

// SQL Request

//Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY ,ResultSet.CONCUR_UPDATABLE);
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs = null;
rs = stmt.executeQuery("SELECT * FROM t_test WHERE file_ID='0001'");
if(rs.next()){
rs.updateString("file_name","davidtest");
rs.updateRow();
}
...全文
779 11 打赏 收藏 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
jackyhj 2002-05-27
  • 打赏
  • 举报
回复
这个问题在java api文档中有过解释,现提供如下:
With the addition of new functionality in the JDBC 2.0 API, it is possible for an application to request features that a DBMS or driver do not support. If the driver does not support scrollable result sets, for example, it may return a forward-only result set. Also, some queries will return a result set that cannot be updated, so requesting an updatable result set would have no effect for those queries. A general rule is that a query should include the primary key as one of the columns it selects, and it should reference only one table.

New methods in the JDBC 2.0 API let an application discover which result set features a driver supports. If there is any doubt about whether a feature is supported, it is advisable to call these methods before requesting the feature. The following DatabaseMetaData methods indicate whether a driver supports a given result set type or a given result set concurrency:

DatabaseMetaData.supportsResultSetType - returns a boolean indicating whether the driver supports the given result set type
DatabaseMetaData.supportsResultSetConcurrency - returns a boolean indicating whether the driver supports the given concurrency type in combination with the given result set type
The following ResultSet methods return the result set type and result set concurrency for the particular result set on which the method is called:

ResultSet.getType - returns the type of this result set
ResultSet.getConcurrency - returns the concurrency mode of this result set
If an application specifies a scrollable result set and the driver does not support scrolling, the driver will issue a warning on the Connection object that produced the statement and return a result set that is forward-only. Even if the driver supports scrollable result sets, it is possible for an application to request a scrollable type that the driver does not support. In such a case, the driver will issue an SQLWarning on the Connection object that produced the statement and return a scrollable result set of a type that it does support, even if it differs from the exact type requested. For example, if an application requests a TYPE_SCROLL_SENSITIVE result set and the driver does not support that type, it could return a TYPE_SCROLL_INSENSITIVE result set if it supports that type. The driver would also alert the application that it did not return the exact type requested by issuing an SQLWarning on the Connection object that produced the statement requesting the unsupported result set type.

Similarly, if an application specifies an updatable result set, a driver that does not support updatable result sets will issue an SQLWarning on the Connection object that produced the statement and return a read-only result set. If the application requests both an unsupported result set type and an unsupported concurrency type, the driver should choose the result set type first.

In some situations, a driver may need to choose an alternate result set type or concurrency type at statement execution time. For example, a SELECT statement that contains a join over multiple tables might produce a result set that is not updatable. In such a situation, the driver will issue an SQLWarning on the Statement, PreparedStatement, or CallableStatement object that tried to create the result set instead of issuing it on the Connection object. The driver will then choose an appropriate result set type and/or concurrency type according to the guidelines in the preceding two paragraphs.
问题就是由于数据库驱动的问题,你可以通过rs.getConcurrency()查看当前记录集的游标类型,如果是ResultSet.CONCUR_UPDATABLE,表示可以做更新,但如果是ResultSet.CONCUR_READ_ONLY,就表示不能做更改数据库操作。
明白了么?
huangzt 2002-05-27
  • 打赏
  • 举报
回复
解决的方法是:

不要用select * ...作查询,
而要用select <直接写出所有字段>的方式.
huangzt 2002-05-27
  • 打赏
  • 举报
回复
可怜的人啊,
想当年我也遇到相同的问题,
往事不堪回首,

skyyoung 2002-05-17
  • 打赏
  • 举报
回复
Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY ,ResultSet.CONCUR_UPDATABLE);

if(rs.next()){
rs.updateString("file_name","davidtest");
}
rs.updateRow();

这样行吗?

---------------
shmilu@sina.com
jackyhj 2002-05-17
  • 打赏
  • 举报
回复
我用oracle试过了,是有这样的错误,应该是数据库驱动的问题,可以换换其他的驱动试试看,因为我现在用的驱动是瘦客户机的驱动连接
bellfeel 2002-05-14
  • 打赏
  • 举报
回复
为何没人回答我的问题呀?
我用mysql测试可以通过,但在oracle下却出现此问题,是数据库的问题??
bellfeel 2002-05-14
  • 打赏
  • 举报
回复
我是用来上载文件用的,先保存文本数据,再保存blob数据呀,请教了,各位。
jackyhj 2002-05-14
  • 打赏
  • 举报
回复
为什么一定要这样做,直接用update语句不就可以了么
jackyhj 2002-05-14
  • 打赏
  • 举报
回复
它已经改过来了,不是注释了么!
worldheart 2002-05-14
  • 打赏
  • 举报
回复
这句话错了,
(ResultSet.TYPE_FORWARD_ONLY ,ResultSet.CONCUR_UPDATABLE);

需要改为:
(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);

bellfeel 2002-05-14
  • 打赏
  • 举报
回复
我用的是oracle8.17
内容概要:本文研究了计及需求侧响应的日前、日内两阶段鲁棒备用优化方法,旨在应对高比例可再生能源接入背景下电力系统中存在的不确定性问题。通过构建两阶段鲁棒优化模型,将日前调度作为第一阶段决策,日内调整作为第二阶段修正,充分考虑风电、光伏等出力波动以及负荷变化带来的影响。模型引入需求侧响应机制,利用可调节负荷参与系统备用,提升系统的灵活性与鲁棒性。采用列与约束生成(C&CG)算法对两阶段鲁棒优化问题进行求解,并通过Matlab编程实现,结合标准测试系统进行仿真分析,验证了所提方法在降低运行成本、提高可再生能源消纳能力和增强系统可靠性方面的有效性。; 适合人群:具备电力系统优化、运筹学及Matlab编程基础的研究生、科研人员及从事能源系统规划与运行的专业技术人员。; 使用场景及目标:①应用于含高比例可再生能源的电力系统调度决策,提升调度方案的鲁棒性;②为需求侧资源参与电力系统备用提供建模与求解工具;③支撑科研教学中关于两阶段鲁棒优化、C&CG算法实现的学习与实践。; 阅读建议:建议读者结合Matlab代码深入理解模型构建与求解流程,重点关注不确定性集合的刻画方式、需求侧响应的建模方法以及C&CG算法的迭代逻辑,宜配合相关优化理论资料进行系统学习。

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧