DataIntegrityViolationException異常:java利用mymatis連線資料庫異常

菜鳥Octopus發表於2018-08-22
異常出現的資訊 DataIntegrityViolationException:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: 
### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`data`.`orderdetail`, CONSTRAINT `FK_orderdetail_2` FOREIGN KEY (`items_id`) REFERENCES `items` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION)
### The error may involve cn.itcast.ssm.mapper.ItemsMapper.deleteItemById-Inline
### The error occurred while setting parameters
### SQL: delete from items where id=?
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`data`.`orderdetail`, CONSTRAINT `FK_orderdetail_2` FOREIGN KEY (`items_id`) REFERENCES `items` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION)
; SQL []; Cannot delete or update a parent row: a foreign key constraint fails (`data`.`orderdetail`, CONSTRAINT `FK_orderdetail_2` FOREIGN KEY (`items_id`) REFERENCES `items` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION); nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`data`.`orderdetail`, CONSTRAINT `FK_orderdetail_2` FOREIGN KEY (`items_id`) REFERENCES `items` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:927)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

出現這種問題是資料庫表與別的表有想連線關係,如果別的表沒有用,將別的表刪除就好了,就可以操作這個表!

相關文章