【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


使用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 syntax to use near 'update
                goods g
            SET
                update_date = '2019-03-19 17:16:05.918',
                updat' at line 28

 

但是檢查了以后,28行並沒有錯誤

使用【https://www.cnblogs.com/sxdcgaq8080/p/9100178.html】 打印了sql,發現sql如下,也沒有問題:

UPDATE goods
SET update_date = '2019-03-19 17:12:30',
 update_id = 'defUserId',
 enabled = 1,
 NAME = '李鋼的屏幕維修服務',
 py_all = 'ligangdepingmuweixiufuwu',
 py_head = 'lgdpmwxfw',
 outer_code = '345345345345',
 mnemonic_code = '',
 del_flag = 0,
 enabled_flag = 1,
 goods_type_uid = 'a5cd4e8cc75456e7',
 url = '',
 bar_cide = '',
 sale_price = NULL,
 integral = 0,
 scan_name = '李鋼的屏幕維修服務',
 brand_uid = '01',
 en_name = '李鋼的屏幕維修服務'
WHERE
    outer_id = '345345345345'
AND tenement_id = 'test_tenement_123';

UPDATE goods
SET update_date = '2019-03-19 17:12:30',
 update_id = 'defUserId',
 enabled = 1,
 NAME = '黑莓798',
 py_all = 'heimei798',
 py_head = 'hm798',
 outer_code = '453975973361094656',
 mnemonic_code = '',
 del_flag = 0,
 enabled_flag = 1,
 goods_type_uid = 'a5cd4e8cc75456e7',
 url = '',
 bar_cide = '',
 sale_price = NULL,
 integral = 0,
 scan_name = '黑莓798',
 brand_uid = '01',
 en_name = '黑莓798'
WHERE
    outer_id = '453975973361094656'
AND tenement_id = 'test_tenement_123';

UPDATE goods
SET update_date = '2019-03-19 17:12:30',
 update_id = 'defUserId',
 enabled = 1,
 NAME = '測試商品',
 py_all = 'ceshishangpin',
 py_head = 'cssp',
 outer_code = 'CS001',
 mnemonic_code = '',
 del_flag = 0,
 enabled_flag = 1,
 goods_type_uid = 'a5cd4e8cc75456e7',
 url = '',
 bar_cide = '',
 sale_price = NULL,
 integral = 0,
 scan_name = '測試商品',
 brand_uid = '01',
 en_name = 'test 
product'
WHERE
    outer_id = 'CS001'
AND tenement_id = 'test_tenement_123'
View Code

 

 

報錯原因:

是因為spring boot配置文件中,關於數據庫的連接配置,並沒有允許進行批量更新的操作

 

 

 

解決方法:

將數據庫配置修改為 
jdbc.url=jdbc:mysql://127.0.0.1:3306/datebase?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&allowMultiQueries=true 新增了 &allowMultiQueries=true 意為 允許批量更新

 

 

需要注意的是:

加了&allowMultiQueries=true 意為 允許批量更新

但是此時如果再想在spring boot中運行mybatis的時候想打印出來sql,就已經不起作用了。

此時按照
https://www.cnblogs.com/sxdcgaq8080/p/9100178.html
配置的,在spring boot中打印sql語句,就無效了

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱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 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 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; che com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax;問題的解決 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 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", org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manu 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
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM