1、字段名报错
控制台中报错:
java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order' at line 1
在浏览器中报错
org.springframework.jdbc.BadSqlGrammarException:
###查询数据库时出错。原因:java.sql.SQLSyntaxErrorException:您的SQL语法有错误。检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的“ leave”附近使用
###错误可能存在于com / mapper / LeaveMapper.xml中
###错误可能涉及defaultParameterMap
###设置参数时发生错误
### SQL:从订单中选择*;
###原因:java.sql.SQLSyntaxErrorException:您的SQL语法有错误。检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的“ order”附近使用
; 错误的SQL语法[]; 嵌套的异常是java.sql.SQLSyntaxErrorException:SQL语法有错误。检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的“ order”附近使用
- 出现这种错误不是语法的问题,而是你要操作的数据表“order”不能使用,因为order的数据库的关键字
- 解决方案:把order表的名字改一下,同时在sql语句中改成同样的表名
2、外键约束
控制台中报错:
java.sql.SQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`hotelsystem`.`customer`, CONSTRAINT `customer_room_roomId` FOREIGN KEY (`roomId`) REFERENCES `room` (`roomid`))
; SQL []; Cannot delete or update a parent row: a foreign key constraint fails (`hotelsystem`.`customer`, CONSTRAINT `customer_room_roomId` FOREIGN KEY (`roomId`) REFERENCES `room` (`roomid`)); nested exception is java.sql.SQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`hotelsystem`.`customer`, CONSTRAINT `customer_room_roomId` FOREIGN KEY (`roomId`) REFERENCES `room` (`roomid`))] with root cause
java.sql.SQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`hotelsystem`.`customer`, CONSTRAINT `customer_room_roomId` FOREIGN KEY (`roomId`) REFERENCES `room` (`roomid`))
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:117)
关键词foreign key,表示该报错的原因是外键约束,字段的值无法被修改或删除。该字段被其他表作为外键引用,只要找到对应的表删除外键约束就可解决该问题
ALTER TABLE XXX(表名) DROP CONSTRAINT XXX(外键名)