验证MySQL数据库在java应用jdbc参数不同配置情况下的表现。
通过配置文件,确定不同的jdbc参数组合:
mysql | ||||
---|---|---|---|---|
rewriteBatchedStatements | False | False | True | True |
allowMultiQueries | False | True | False | True |
批量insert(batch statements) | 正常 | 正常 | 正常 | 正常 |
多条sql(multi query) | 报错 | 正常 | 报错 | 正常 |
需要用分号,多条sql提交执行的时候,jdbc参数设置allowMultiQueries=true
详细如下:
测试程序报错:(批量写入正常,多语句执行报错)
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 'select count(*) from tinsert;insert into tinsert (id,a) values(0,1),(0,2);select' at line 1;
general_log看到:批量insert语句,实际上客户端分成多条发起请求;
JDBC:rewriteBatchedStatements=false&allowMultiQueries=true
程序正常执行无报错。
测试程序报错:(批量写入正常,多语句执行报错)
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 'select count(*) from tinsert;insert into tinsert (id,a) values(0,1),(0,2);select' at line 1;
程序正常执行无报错。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。