0
私のプログラムでは、テーブルtbl_name
にレコードを挿入します。しかし、私は '主キーの重複エントリ'エラーを持って、これは私が困惑させる、ここで私のコードとエラーです。Mysql主キーの重複エントリ(AUTO_INCREMENT)
表:
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();
}
エラー:502に
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}