Exception in thread "main" com.mysql.jdbc.NotUpdatable: Result Set not updatable (referenced table
has no primary keys).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.
at com.mysql.jdbc.UpdatableResultSet.generateStatements(UpdatableResultSet.java:589)
at com.mysql.jdbc.UpdatableResultSet.syncUpdate(UpdatableResultSet.java:1493)
at com.mysql.jdbc.UpdatableResultSet.updateString(UpdatableResultSet.java:2450)
at com.mysql.jdbc.UpdatableResultSet.generateStatements(UpdatableResultSet.java:589)
at com.mysql.jdbc.UpdatableResultSet.syncUpdate(UpdatableResultSet.java:1493)
at com.mysql.jdbc.UpdatableResultSet.updateString(UpdatableResultSet.java:2450)
at com.database.db.MySQLConnectionTest.main(MySQLConnectionTest.java:63)
备注:出现以上错误的原因主要有多种情况:
1)数据库表没有主键造成的(博主的就是这个问题),添加一个主键即可。
2)在createStatement方法或者prepareStatemen方法中没有添加ResultSet.CONCUR_UPDATABLE属性
3)修改表只能在一个表中进行,不能同时修改多个表
本文探讨了在使用MySQL时遇到的ResultSet not updatable错误的原因及解决方法,重点介绍了添加主键、设置ResultSet属性和确保操作在单一表内进行的重要性。

被折叠的 条评论
为什么被折叠?



