赞
踩
踩坑日记。数据库提示错误的查询语句。但我看了和数据库表中的字段名是一模一样的,经过我的反复排查,后知后觉的发现原来desc是数据库的
关键字
呀。desc是mysql中的降序关键字,只要把desc换一个名字就好了。最开始反复提示near“desc xxxx”,提示在desc附近,没往这边想。然后其他的就好好对照看是不是自己写错了。
- 看网上还有一种说法就是你在查询的时候可能涉及到一个xml的<select>或者其他标签同时有多条查询语句。那么你就在你的数据库地址配置时多加一条语句&allowMultiQueries=true:
url: jdbc:mysql://localhost:3306/testgenerate?serverTimezone=GMT%2b8&allowMultiQueries=true
- 1
2022-11-30 09:27:19.151 ERROR 2572 — [nio-9090-exec-2] 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 ‘desc
,address,shop,shopid FROM product’ at line 1
The error may exist in com/example/springboot/mapper/ProductMapper.java (best guess)
The error may involve defaultParameterMap
The error occurred while setting parameters
SQL: SELECT id,name,category,desc,address,shop,shopid FROM product
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 ‘desc,address,shop,shopid FROM product’ 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 ‘desc,address,shop,shopid FROM product’ 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 ‘desc,address,shop,shopid FROM product’ at line 1
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。