本文主要是介绍DuplicateKeyException异常处理,向数据库添加数据失败,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
问题描述
向数据库中添加数据失败
问题报错
### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '0-0' for key 'PRIMARY'
### The error may involve com.leyou.item.mapper.BrandMapper.insertCategoryBrand-Inline
### The error occurred while setting parameters
### SQL: insert into tb_category_brand(category_id, brand_id) values (category_id=?,brand_id=?)
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '0-0' for key 'PRIMARY'
; ]; Duplicate entry '0-0' for key 'PRIMARY'; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '0-0' for key 'PRIMARY'] with root cause
问题原因
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry ‘0-0’ for key ‘PRIMARY’
说明在数据库中这一列,它为空!因为主键在数据库中不能为空,所以出现下面异常;就需要把主键设置为不为空就可以解决了
数据库中表的数据
这篇关于DuplicateKeyException异常处理,向数据库添加数据失败的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!