前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >MySQL多语句执行测试

MySQL多语句执行测试

原创
作者头像
胖五斤
发布2023-09-19 10:53:39
发布2023-09-19 10:53:39
3500
举报
文章被收录于专栏:一涨知识胖五斤

测试目的

验证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

测试过程

详细如下:

JDBC:rewriteBatchedStatements=false&allowMultiQueries=false

测试程序报错:(批量写入正常,多语句执行报错)

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

程序正常执行无报错。

JDBC:rewriteBatchedStatements=true&allowMultiQueries=false

测试程序报错:(批量写入正常,多语句执行报错)

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;

JDBC:rewriteBatchedStatements=true&allowMultiQueries=true

程序正常执行无报错。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
LV.
这个人很懒,什么都没有留下~
目录
  • 测试目的
  • 测试程序
  • 测试结论
    • 建议
    • 测试过程
      • JDBC:rewriteBatchedStatements=false&allowMultiQueries=false
      • JDBC:rewriteBatchedStatements=true&allowMultiQueries=false
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档