Result Set not updatable解决办法

本文针对在使用ResultSet进行更新操作时出现的错误进行了详细说明,并提供了解决方案。该错误主要由于ResultSet不可更新引起,通常涉及从单一表中选择所有主键且不使用函数的情况。通过设置PreparedStatement的类型为TYPE_SCROLL_INSENSITIVE和CONCUR_UPDATABLE,可以有效解决问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ResultSet更新操作时产生错误。
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.
解决办法:
ps = getConnection().prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

这是数据区表结构:CREATE TABLE `t_framehead` ( `N_FRAMEHEAD_ID` int NOT NULL AUTO_INCREMENT COMMENT '帧结构ID,自增主键', `N_TYPE` tinyint NOT NULL COMMENT '类型,1=遥测,2=遥控,3=其他', `D_CREATE` datetime NOT NULL COMMENT '创建时间,不能为空,系统创建时的时间', `VC_DESC` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '简述,简单描述,如适用项目等,允许为空', PRIMARY KEY (`N_FRAMEHEAD_ID`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC; // 封装请求函数 export const frameheadAPI = (data) => { return request({ url: '/edit/framehead', method: 'POST', data }) } data示例:{desc: “”,type: 2} 写一份后端接口,springboot3,rest风格 ,controller,entity,mapper,service(impl),xml全都要,结果封装:public class Result { private Integer code; private String msg; private Object data; public static Result success() { Result result = new Result(); result.setCode(200); result.setMsg("请求成功"); return result; } public static Result success(Object data) { Result result = new Result(); result.setCode(200); result.setMsg("请求成功"); result.setData(data); return result; } public static Result error() { Result result = new Result(); result.setCode(500); result.setMsg("系统错误"); return result; } public static Result error(Integer code,String msg) { Result result = new Result(); result.setCode(code); result.setMsg(msg); return result; } public static Result error(Integer code,String msg,Object data) { Result result = new Result(); result.setCode(code); result.setMsg(msg); result.setData(data); return result; } public Integer getCode() { return code; } public void setCode(Integer code) { this.code = code; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public Object getData() { return data; } public void setData(Object data) { this.data = data; } }
03-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值