org.mozilla.javascript.WrappedException: Wrapped org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [select count(1) from (select a.id, a.contract_id contractId, a.product_id productId, a.purchase_num purchaseNum, a.purchase_price purchasePrice, a.remark, b.product_name productName, b.spec_code specCode, c.type_name typeName, d.unit_code unitCode from mes-214820524.wms_pur_list_214820524 a, mes-214820524.wms_product_214820524 b, mes-214820524.wms_product_class_214820524 c, mes-214820524.wms_unit_code_214820524 d where a.product_id=b.id and b.product_class_id = c.id and b.unit_code_id=d.id and a.contract_id= '3b353514235f4a8da8dbcdbcbb5a643e' ) t1]; 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 '-214820524.wms_pur_list_214820524 a, mes-214820524.wms_product_214820524 b,' at line 11 (JavaScriptScriptParse#22)at帮我分析一下这段错误,并告诉我怎么修改
时间: 2024-02-26 16:54:05 浏览: 170
这个错误的原因是 SQL 语句的语法有误,具体来说是在 SQL 语句中的表名不正确。
从错误信息中可以看到,SQL 语句的表名是 "mes-214820524.wms_pur_list_214820524","mes-214820524.wms_product_214820524","mes-214820524.wms_product_class_214820524","mes-214820524.wms_unit_code_214820524",这些表名中包含了横杠符号 "- "。
MySQL 中的表名不能包含横杠符号 "- ",所以需要修改 SQL 语句中的表名,将横杠符号替换为下划线符号 "_ "即可。
修改后的 SQL 语句如下所示:
select count(1) from (select a.id, a.contract_id contractId, a.product_id productId, a.purchase_num purchaseNum, a.purchase_price purchasePrice, a.remark, b.product_name productName, b.spec_code specCode, c.type_name typeName, d.unit_code unitCode from mes_214820524.wms_pur_list_214820524 a, mes_214820524.wms_product_214820524 b, mes_214820524.wms_product_class_214820524 c, mes_214820524.wms_unit_code_214820524 d where a.product_id=b.id and b.product_class_id = c.id and b.unit_code_id=d.id and a.contract_id= '3b353514235f4a8da8dbcdbcbb5a643e' ) t1
请注意,修改 SQL 语句时需要谨慎,确保修改后的语句语法正确,否则可能会导致其他错误。
阅读全文