当前位置:   article > 正文

Error querying database. Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syn

error querying database. cause: java.sql.sqlsyntaxerrorexception: you have a

踩坑日记。数据库提示错误的查询语句。但我看了和数据库表中的字段名是一模一样的,经过我的反复排查,后知后觉的发现原来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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/594033
推荐阅读
相关标签
  

闽ICP备14008679号