一、问题表现:
批量插入时报错,错误如下:
### Cause: 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 ''2020-06-02 00:00:00',
'2020-06',
4,
'1111',' at line 2
; bad SQL grammar [];

二、分析过程
数据无问题,单条数据插入也正常,就是在多行insert时报错,xml的脚本如下:
<insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
INSERT INTO `xxxx`
(<include refid="Insert_Column_List"></include>)
VALUES
<foreach collection="list" separator=";" item="p">
(
#{p.date},
#{p.accountPeriod}
)
批量插入MySQL错误解析

本文解析了批量插入MySQL数据时报错的原因,指出XML脚本中使用分号作为数据分隔符的问题,并提供了解决方案,即将分隔符改为逗号。
最低0.47元/天 解锁文章
1322

被折叠的 条评论
为什么被折叠?



