2017-11-18 11 views
0

In meinem Programm, ich füge Datensatz in Tabelle tbl_name. Aber ich habe einen 'Duplicate-Eintrag für Primärschlüssel' Fehler, das macht mich verwirrt, Hier ist mein Code und Fehler.Mysql Doppeleintrag für Primärschlüssel (AUTO_INCREMENT)

Tabelle:

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' 

Code:

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(); 
} 

Fehler:

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} 

Antwort

0

Increment Primärschlüsselspalte Wert auf 502. Es beginnt zu arbeiten.

Verwandte Themen