2021-06-24

mysql 批量更新 update foreach 报错

<!--    通过商品ID和仓库编码更新仓库多条商品库存量    -->
    <update id="updateStockGoodsList">
        <foreach collection="list" item="StockGoods" index="index">
            update stock_goods
            <set>
                <if test="StockGoods.procurePricing != null and StockGoods.procurePricing != ''">
                    procure_pricing = #{StockGoods.procurePricing},
                </if>
                <if test="StockGoods.goodsPricing != null and StockGoods.goodsPricing != ''">
                    goods_pricing = #{StockGoods.goodsPricing},
                </if>
                goods_quantity = #{StockGoods.goodsQuantity}, update_time = #{StockGoods.updateTime}, operator_id = #{StockGoods.operatorId}
            </set>
            where goods_id = #{StockGoods.goodsId} and stock_code = #{StockGoods.stockCode};
        </foreach>
    </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 'update stock_goods\n SET goods_quantity = 100, update_time = ‘2021-06’ at line 5\r\n### The error may exist in file [D:\Java\JavaProjects\RuoYi-Vue\ruoyi-system\target\classes\mapper\system\StockGoodsMapper.xml]\r\n### The error may involve defaultParameterMap\r\n### The error occurred while setting parameters\r\n### SQL: update stock_goods SET goods_quantity = ?, update_time = ?, operator_id = ? where goods_id = ? and stock_code = ?; update stock_goods SET goods_quantity = ?, update_time = ?, operator_id = ? where goods_id = ? and stock_code = ?; update stock_goods SET goods_quantity = ?, update_time = ?, operator_id = ? where goods_id = ? and stock_code = ?;\r\n### 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 'update stock_goods\n SET goods_quantity = 100, update_time = ‘2021-06’ at line 5\n; 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 'update stock_goods\n SET goods_quantity = 100, update_time = ‘2021-06’ at line 5"

解决方案:&allowMultiQueries=true

url: jdbc:mysql://localhost:3306/workorderDemo?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值