com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '1' for key 'PRIMARY'at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)at java.lang.reflect.Constructor.newInstance(Unknown Source)at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)at com.mysql.jdbc.Util.getInstance(Util.java:387)at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:932)at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478)at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625)at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2551)at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073)at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009)at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5094)at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994)at org.dao.LoginDao.addInfo(LoginDao.java:73)at org.servlet.LeaveMessageServlet.doGet(LeaveMessageServlet.java:39)at org.servlet.LeaveMessageServlet.doPost(LeaveMessageServlet.java:44)at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
5 回答
慕少森
TA贡献2019条经验 获得超9个赞
看这个帖子,帮你问了下朋友
http://www.yl1001.com/group_article/5461468980778720.htm?classic_id=4941468982929372#comment_4941468982929372
这里只有你的建表语句,并没有你的插入数据语句,所以只能推断你的场景了。
messagess表的主键是id,loginss的主键也是id;两个表的id都是自增的,这样的话插入的时候就不要给id赋值,跳过他会自动赋值。
报错的原因:表中已经有id为1的记录,你继续往里插新记录了,但是id还是1.
解决方法:插入数据跳过id,或者用insert ingore(已有记录不插入新记录)
添加回答
举报
0/150
提交
取消