在我的程序中,我将记录插入表tbl_name
。但我得到了一个重复的主键条目'错误,这让我感到困惑,这是我的代码和错误。
表:
CREATE TABLE `tbl_name` (
`id` int(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
`name` varchar(255) NOT NULL DEFAULT '' COMMENT 'name',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=514 DEFAULT CHARSET=utf8 COMMENT='table'
代码:
public Integer batchInsert() {
List<Object[]> updateList = Arrays.asList("name1","name2");
if (updateList.size() > 0) {
String insertSql = "insert into tbl_name (`name`) values (?)";
jdbcTemplate.batchUpdate(insertSql, updateList);
}
return updateList.size();
}
错误:
17-11-18.00:26:00.262 [pool-5-thread-1] ERROR ApprovalService - ERROR message: {"code":1,"message":"PreparedStatementCallback; SQL []; Duplicate entry '501' for key 'tbl_name_id'; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '501' for key 'tbl_name_id'","errorStackTraceMessage":null}
答案 0 :(得分:0)
将主键列值增加到502.它将开始工作。