sql语句之坑

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(外键名)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在使用iBatis时,可以通过配置log4j来输出SQL语句的调试信息。在log4j.properties文件中,可以设置不同的日志级别来控制输出的详细程度。例如,设置以下内容可以输出SQL语句的调试信息: ``` # Preparing Statement: SQL log4j.logger.java.sql.Connection = DEBUG # Executing Statement: SQL / Parameters / Types log4j.logger.java.sql.Statement = DEBUG log4j.logger.java.sql.PreparedStatement = DEBUG # ResultSet: Header / Result log4j.logger.java.sql.ResultSet = DEBUG ``` 这样配置后,在生产环境中就可以输出SQL语句的调试信息了。\[2\]同时,关于iBatis中的特殊字符,有两个常见的符号:#和$。#会将传入的数据加上引号,可以避免SQL注入问题,通常用于传递参数值。而$会直接将传入的数据放入SQL语句中,适用于一些特殊情况,比如在orderby后面或者where xx in ()的括号里等。\[3\] #### 引用[.reference_title] - *1* [记一个-ibatis中SQL语句带#](https://blog.csdn.net/babdpfi/article/details/124302325)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [ibatis运行的SQL语句的输出——通过配置log4j](https://blog.csdn.net/qq_28867949/article/details/78393267)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [使用ibatis的sql语句](https://blog.csdn.net/m0_67379678/article/details/126739524)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值