org.springframework.dao.DuplicateKeyException: PreparedStatementCallback; SQL [insert into tab_user(

PreparedStatementCallback; SQL [insert into tab_user(username,password,name,birthday,sex,telephone,email,status,code) values(?,?,?,?,?,?,?,?,?)]; Duplicate entry ‘zhangsan’ for key ‘AK_nq_username’; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry ‘zhangsan’ for key ‘AK_nq_username’

描述 服务器遇到一个意外的情况,阻止它完成请求。

Exception

org.springframework.dao.DuplicateKeyException: PreparedStatementCallback; SQL [insert into tab_user(username,password,name,birthday,sex,telephone,email,status,code) values(?,?,?,?,?,?,?,?,?)]; Duplicate entry ‘zhangsan’ for key ‘AK_nq_username’; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry ‘zhangsan’ for key ‘AK_nq_username’
org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:239)
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:660)
org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:909)
org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:970)
org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:980)
target.dao.impl.userdaoimpl.save(userdaoimpl.java:35)
target.service.impl.Userserviceimpl.regist(Userserviceimpl.java:25)
target.web.servlet.registerUserServlet.doPost(registerUserServlet.java:64)
javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

Root Cause

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry ‘zhangsan’ for key ‘AK_nq_username’
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:423)
com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
com.mysql.jdbc.Util.getInstance(Util.java:386)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1041)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4190)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4122)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2818)
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2157)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2460)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2377)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2361)
com.alibaba.druid.pool.DruidPooledPreparedStatement.executeUpdate(DruidPooledPreparedStatement.java:253)
org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:916)
org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:909)
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:644)
org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:909)
org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:970)
org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:980)
target.dao.impl.userdaoimpl.save(userdaoimpl.java:35)
target.service.impl.Userserviceimpl.regist(Userserviceimpl.java:25)
target.web.servlet.registerUserServlet.doPost(registerUserServlet.java:64)
javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

提交表单的时候 后台没有验证好 提交了数据 但是表中有唯一约束 报的sql 错误

你可能感兴趣的:(杂七杂八)