*I've been, I've fought, I don't care about the ending*
最近在写一个小的项目时,发现一个问题,mybatis实现了批量插入,但是运行的时候出现了插入语句错误的mysql的经典提示,具体如下:
- mybatis的xml如下
向不同的表插入数据,可以利用;进行分隔,前端传过来的值是正确的,但是到这里却插入失败,具体如下:
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 ''
INSERT INTO service_input(2073,‘iphone12 pro’)......
上述能够出现2073,iphone12 pro的字样,说明值的传输是没有错误的,但是到mysql中发现数据是没有的,于是开始排查语句是不是出现了问题
这里的批量插入是没有问题的,那么问题就只能够是配置文件出了问题,查看db.properties
果然,没有打开批量更新的开关,所以默认只允许插入一条。更改为如下配置:
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/service_L?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
jdbc.username=root
jdbc.password=root
成功解决!
*Thanks for reading*