SQL异常记录

在2022年3月16日23:30,一个应用程序遇到了一个SQL解析异常,原因是试图使用'like'这个MySQL关键字作为表字段。错误信息指出在查询时遇到了语法错误,提示需要检查与MySQL服务器版本相应的手册以获取正确的SQL语法。解决方案是修改使用了关键字的字段名称。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

异常如下

2022-03-16 23:30:34.421 WARN 7452 — [http-nio-8084-exec-1]
c.b.m.e.p.i.PaginationInnerInterceptor : optimize this sql to a
count sql has exception, sql:"SELECT
id,parent_id,user_id,song_id,song_list_id,content,type,like,create_time,update_time,is_delete
FROM comment WHERE is_delete=0

AND (song_list_id = ?)", exception:
net.sf.jsqlparser.parser.ParseException: Encountered unexpected token:
“like” “LIKE”
at line 1, column 64.

Was expecting one of:

2022-03-16 23:30:34.634 ERROR 7452 — [http-nio-8084-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException:
‘’### Error querying database. Cause: 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 'like,create_time,update_time,is_delete FROM comment
WHERE is_delete=0

AND (’ at line 1 ‘’### The error may exist in
com/liyue/music/dao/CommentMapper.java (best guess) ‘’### The error
may involve defaultParameterMap ‘’### The error occurred while setting
parameters ‘’### SQL: SELECT COUNT(*) FROM (SELECT
id,parent_id,user_id,song_id,song_list_id,content,type,like,create_time,update_time,is_delete
FROM comment WHERE is_delete=0 AND (song_list_id = ?)) TOTAL ‘’###
Cause: 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
'like,create_time,update_time,is_delete FROM comment WHERE
is_delete=0

AND (’ at line 1 ; bad SQL grammar []; nested exception is
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
'like,create_time,update_time,is_delete FROM comment WHERE
is_delete=0

AND (’ at line 1] with root cause

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
'like,create_time,update_time,is_delete FROM comment WHERE
is_delete=0

AND (’ at line 1 at
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
~[mysql-connector-java-8.0.22.jar:8.0.22] at
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
~[mysql-connector-java-8.0.22.jar:8.0.22] at
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
~[mysql-connector-java-8.0.22.jar:8.0.22] at
com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
~[mysql-connector-java-8.0.22.jar:8.0.22] at
com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:370)
~[mysql-connector-java-8.0.22.jar:8.0.22]

问题

犯了最基本的错误,用了MySQL关键字做表字段,找到对应的字段修改一下就好了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值