java com。mysql。jdbc。例外。jdbc4。MySQLIntegrityConstraintViolationException:键“PRIMARY”的重复条目“0”,其根本原因是
当我试图将数据插入数据库时,我得到了以下错误:
SEVERE: Servlet.service() for servlet [jsp] in context with path [] threw exception [javax.servlet.ServletException: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:
Duplicate entry '0' for key 'PRIMARY'] with root cause com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:
Duplicate entry '0' for key 'PRIMARY'
这是我的问题
insert into tablename values(0,'(col name)');
# 1 楼答案
表的第一列是主键。所以它不允许有重复的值。但从您的SQL查询中,我知道您每次都将0作为硬代码值传递。 这就是错误的原因