zoukankan      html  css  js  c++  java
  • 遇到的错误:Mysql 报错Duplicate entry '值' for key '字段名'的解决

    ### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'admin' for key 'user_name_unique'
    ### The error may involve com.mmall.dao.UserMapper.insert-Inline
    ### The error occurred while setting parameters
    ### SQL: insert into mmall_user (id, username, password,        email, phone, question,        answer, role, create_time,        update_time)     values (?, ?, ?,        ?, ?, ?,        ?, ?, now(),       now())
    ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'admin' for key 'user_name_unique'
    ; SQL []; Duplicate entry 'admin' for key 'user_name_unique'; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'admin' for key 'user_name_unique'] with root cause
     com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'admin' for key 'user_name_unique'
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
      at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
      at com.mysql.jdbc.Util.getInstance(Util.java:408)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3978)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3914)
      at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530)

    二、问题解释:
    Duplicate entry...for key...的错误原因是主键的唯一值重复,在对数据库进行修改、插入操作时,一但主键的唯一值重复就会报此错误,有时在表中存在多个相同主键时,对表操作报此错误,
    (ps:我的表中数据主键有两个相同的主键,在使用把一张表数据导入到另一张表的数据时使用主键字段结果报错。)
    三、解决方法:
    第一种,如果主键不是必需要的字段,就不用主键
    第二种,先把表中重复去除,在进行操作

  • 相关阅读:
    UVA
    [CQOI2018] 社交网络
    UVA
    51nod 1314 定位系统
    51nod 1211 数独
    51nod 1392 装盒子
    51nod1253 Kundu and Tree
    51nod1313 完美串
    51nod1039 x^3 mod p
    51nod1369 无穷印章
  • 原文地址:https://www.cnblogs.com/manmanchanglu/p/12044400.html
Copyright © 2011-2022 走看看