mybatis的報錯總結_____2Error 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 ri


在編寫動態sql時 trim的屬性寫錯了,如下圖:

錯誤示范:

(接口的xml配置文件中:)

1  <update id="modifyBill" parameterType="Bill">
2         update smbms_bill
3         <trim suffix="set" prefixOverrides="," prefix="where id=#{id}">
4         <if test="billCode!=null">billCode=#{billCode},</if>
5             <if test="productName!=null">productName=#{productName},</if>
6             <if test="productDesc!=null">productDesc=#{productDesc}</if>
7         </trim>
8     </update>

報錯日志:

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 'where id=3 billCode='33333',


//可以看到日志中打印出來的sql語句也是有錯的,如下:
### SQL: update smbms_bill          where id=? billCode=?,             productName=?,             productDesc=? set

 

正確的示范:

接口的xml配置文件中:

 <!--最后一個沒有逗號~~~~~-->
    <update id="modifyBill" parameterType="Bill">
        update smbms_bill
        <trim prefix="set" prefixOverrides="," suffix="where id=#{id}">
        <if test="billCode!=null">billCode=#{billCode},</if>
            <if test="productName!=null">productName=#{productName},</if>
            <if test="productDesc!=null">productDesc=#{productDesc}</if>
        </trim>
    </update>

打印出來的sql語句:

[com.xbf.dao.bill.BillMapper.modifyBill]-==>  Preparing: update smbms_bill set billCode=?, productName=?, productDesc=? where id=? 

總結:(網上找的圖,感覺說的很清晰!)

prefix:字首 eg:set

prefixOverrides:字首的替換 eg:  ,

suffix:后綴 eg:where id=#{ id }


免責聲明!

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



猜您在找 mybatis的報錯____3Error 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 [bug] Error updating database. Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MyS 報錯--->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 'delect from testd 空指針和SQL語法錯誤org.springframework.jdbc.BadSqlGrammarException: ### Error updating database. Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that ### Error updating database. Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL 【mybatis】mybatis進行批量更新,報錯:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right SQL Error: 1064, SQLState: 42000 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version mybatis批量更新update-設置多個字段值 報錯 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 SQL語句報錯:You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ERROR 1064 (42000): 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
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM