MySQLIntegrityConstraintViolationException: #23000

限时加码!20+主流AI编程工具免费用 购周边加赠Coding Plan Lite,Claude Code、Cursor等即刻畅享,学习进阶更高效! 阅读详情

闲来无事运行我以前写的代码时,报错MySQLIntegrityConstraintViolationException: #23000.

 一.  异常原因

  插入主键时,表中已有相同的主键,所以报错.插入的新数据,与表的主键唯一约束产生了冲突

  就是新数据的主键在表中已经存在了.

 二. 解决方法

 1.更换插入的主键数据

 2.把主键设置为自动递增,插入数据时不插入主键.

MySQLIntegrityConstraintViolationException:Duplicate entry ‘xxx‘ for key ‘xxx‘异常解决 **报错:Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry ‘xxx’ for key ‘xxx’**异常解决 阅读详情

相关推荐

java.sql.SQLIntegrityConstraintViolationException: #23000

java.sql.SQLIntegrityConstraintViolationException: #23000**异常信息****异常原因****解决方法** 异常信息 ### Cause: java.sql.SQLIntegrityConstraintViolationException: #23000 ; #23000; nested exception is java.sql.SQLIntegrityConstraintViolationException: #23000] with root c

123 4298

mybatis插入数据报错:#23000#22001,1054

Cause: java.sql.SQLIntegrityConstraintViolationException: #23000 我的这个错是由于主键冲突了导致

qq_28646679的博客 8197

Mysql出现问题:ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constrain fail解决方案

Mysql出现问题:ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constrain fail解决方案

小虚竹的专栏 3533

MySQLIntegrityConstraintViolationException异常处理

一、异常现象 操作数据库的时候报出异常MySQLIntegrityConstraintViolationException 错误异常:MySQLIntegrityConstraintViolationException的意思是违反了数据库的完整性约束,在表中建立了唯一索引 Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry

YSY02的博客 2万+

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:Duplicate entry '0' for k

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '0' for key 1 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.

smilelifesky的专栏 5535

MySql常见报错

mysql常见报错

weixin_43277871的博客 665

MySQLIntegrityConstraintViolationException: Column 'roleId' in field list is ambiguous

MySQLIntegrityConstraintViolationException <select id="getRoleByUserAccount" resultType="sun.lab.domain.Role" parameterType="String"> select roleId, r.roleName from role r, user u ...

RaySunWHUT 714

MySQLIntegrityConstraintViolationException: Column ‘DEAL_FLAG‘ cannot be null

MySQL更新语句错误导致非空约束冲突。问题SQL中将字段分隔符错用为AND(正确应为逗号),导致deal_flag未被赋值而违反非空约束。修正方案:将UPDATE语句中的"AND"改为逗号分隔字段,并确保参数非空。典型错误示例:UPDATE table SET field1=1 AND field2=?(错误),正确应为UPDATE table SET field1=1, field2=?。该错误同时提醒需注意:参数校验、避免全表更新、修改后重新编译等问题。关键记忆点:MySQL多字段

devilnumber的博客 220

报错解决:MySQLIntegrityConstraintViolationException: Duplicate entry ‘0‘ for key ‘PRI

而且数据库是使用的雪花算法生成的id,也说明一个问题,在字段里配置id策略的优先高于在配置文件里配置的。注意:此时MySQL数据库的表的id字段是没有设置自增的。但是我的配置文件里是配置里Auto形式的。主要的原因是我的数据库里已经有id为0的数据了,然后我的id默认值也是0,所以就重复了。我尝试在Navicat中将id的默认值去掉,发现去不掉…然后就报了上面这个错,报错很明显,其实就是id重复了。但是重启Navicat后,再设置为0就可以了。注意:直接在Navicat里面加是不生效的!

邵奈一的博客 1096

MySQLIntegrityConstraintViolationException: Column 'ID' in where clause is ambiguous ;

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'ID' in where clause is ambiguous ; SQL []; Column 'ID' in where clause is ambiguous; nested exception is com

Running_dolphin的博客 1905

MySQL插入数据出错及解决方案

项目中对MySQL插入数据的时候,出现错误信息,查阅网上相关文章后解决,记录之,下次供参考。

小天一直在路上 9487

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate ent

错误原因: 代码中遍历插入数据,报错主键重复,mybatis在默认事务中,一个事物执行多条插入语句,mybatis没办法获取插入第一条的主键,我的代码中添加了selectKey标签,所以删除select标签即可解决不能批量插入问题 <insert id="insertSelective" parameterType="com.reada.pojo.ReadaUserTag" > ...

weixin_42671581的博客 5108

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'area' in where clause is ambiguous 翻译就是:where子句中的“area”列是不明确的 是SQL语句关联表查询的时候,因为多张表中都有area字段,所以才会报错说查询条件不知道是查询哪站表里的字段。只要在条件area前加上查询表的别名就行。 例如:s.area = #{areaId} ...

dawnStart的博客 927

springMVC报错:### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:

原因之一是处理中间表时将其中的一个栏位设置为主键了,取消掉这个主键且不需设置为自增长

MoriSummer的博客 2378

mysql 外键冲突_MySQL外键约束冲突异常:com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:...

异常内容Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`book`.`t_order`, CON...

weixin_35962351的博客 1026

采坑笔记--

1,问题描述: 确保数据的唯一性,使用sql 语句 on duplicate unique update ,在mybaits中的mapper文件中拼接sql,出现第二次执行,报 Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '0' for ...

健康平安的活着的专栏 236

30个CSS选择器(updating)

1、*:通用选择器 针对初学者来说,我们还是从简单的开始学起,首先我们来认识下通用选择器,然后再逐步深入学习其它高级的选择器,假如我们想让文档中的每个元素都显示成红色,我们可以这么做: * {color:red;} 通用选择器,可以匹配页面所有的元素。 许多开发者可能会用这个技巧如下代码所示让元素居中,在开发测试阶段固然是好的,但是我不建议这么做,因为这样做会给浏览器增加很大的负担。 * { ...

weixin_44245245的博客 187

**控制台报错: Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your

#解决办法 在XXXmapper.xml文件中找出控制台指定行数,然后删除“}”该大括号

cainiaodejueqi的博客 234

MySQL生产事故一例

背景 分析 解决方案 参考

lonelymanontheway的博客 554
上一篇: 学生信息管理系统(MySQL简单版)
下一篇: 如何理解三层架构
StudentsERE
博客等级 码龄5年 7粉丝 12原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值