[mybatis] sql語句無錯誤,但是執行多條sql語句時,拋出java.sql.SQLSyntaxErrorException


錯誤內容

org.springframework.jdbc.BadSqlGrammarException: ### Error updating 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 '= '553fe0583195819abb6bf1bd2f03d5f32a17f2238f9d23d6c70f67e947e43b33', ' at line 2 ### The error may involve com.slabs.upload.database.mapper.AgentBillDetailDAO.batchUpdateSealIdByPrimaryKey-Inline ### The error occurred while setting parameters ### SQL: update agent_bill_detail seal_id = ?, is_send = ?, receive_time = ? where detail_id = ? ; update agent_bill_detail seal_id = ?, is_send = ?, receive_time = ? where detail_id = ? ### 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 '= '553fe0583195819abb6bf1bd2f03d5f32a17f2238f9d23d6c70f67e947e43b33', ' at line 2 ; 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 '= '553fe0583195819abb6bf1bd2f03d5f32a17f2238f9d23d6c70f67e947e43b33', ' at line 2 


解決方法

本人連接的是mysql數據庫,檢查sql語法並無錯誤。而此處為 多條query語句,報錯信息指向分號后的第二條語句。
判斷可能是連接的datasource默認只允許執行單個query語句。
在連接datasource的url后面增加參數allowMultiQueries=true

url: jdbc:mysql://localhost:3306/node_seal?serverTimezone=UTC&zeroDateTimeBehavior=round&allowMultiQueries=true


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM