遇到這種問題, 是你的資料庫表格那個欄位設定了唯一索引。所以這個欄位新增的資料不能重複。具體可以開啟表,然後點選表格設定
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '測試' for key ' teacher.uk_name'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorsunora.NativeConstructorAccessorImpl.newInstance(NativeConstructorsunora.NativeConstructorAccessorImpl.newInstance(NativeConstructorsunora.NativeConstructor00m.d.p. .newInstance(DelegatingConstructorAccessorImpl .java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNew .mysql.jdbc.Util.getInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
Myat com.mysql.b.java:936)
.java:3976)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3912)
at com.mysql.jdbc.MyMyIO.sendCommand(# at com.mysql.jdbc.MyMyIO.sendCommand(# at com.mysql.jdbc.MyMyIO.sendCommand(# ):555 .mysql。 .java:1858)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1197)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.cute(PromentPexe4ute. at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)## at java.lang.reflect.Method.invoke(Method.java:498)## p. jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59)
at com.sun.proxy.$Proxy118.execute(Unknown Source)
java:47)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)
at sun.reflect.Native#AccessorImpl.insunv)0(Nlect .NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
## at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63)
at com.sun.proxy.$Proxy116.update(Unknown Source)
.555. 。 .update(MybatisCachingExecutor.java:83)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)## ).Defaults (DefaultSqlSession.java:184)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl. invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.mybatis.spring.SqlSessionTemplate$InterSq.gfreceptor.
... 61 more
#點選表格設定以查看索引
以上是Mysql報錯Duplicate entry '值' for key '欄位名稱'如何解決的詳細內容。更多資訊請關注PHP中文網其他相關文章!