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批量更新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 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 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 '"id", Django进行数据迁移时,报错:(1064, "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 '(6) NOT NULL)' at line 1") 插入数据库失败([Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version) Mysql语法错误之> 1064 - 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' MySql 执行语句错误 Err] 1064 - 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 解决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 'order (order_name, customer) Error Code : 1064 You have an error in your SQL syntax; check the manual that corresponds to your My pymysql 1064, 'You have an error in your SQL syntax; check the manual that corresponds to
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM