check the manual that corresponds to your MySQL server version for the right syntax to use near解决方法

如果在代码中使用了批量更新、插入、删除,或者拼接了多条sql一次去执行,但是确遇到了下面的报错:
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 ‘‘upate tablle xxxxxx’’ at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

那么不要着急,先一步一步来排查吧

  1. 检查sql或者代码有没有基本的语法错误
  2. 检查sql中是否存在关键字或者中文字符(这一步需要特别耐心检查)

啥,完成这俩步还报错?
我的sql没问题呀,我的代码没问题呀,打印出来的sql放数据库执行也不报错呀。。。。
为啥还是报错。。。。。。。。。。。。。。。。。
那就换个思路,是不是少了配置或者配置错了
来来来,让我们试试这个:

  1. 在jdbc url参数中加 allowMultiQueries

像下面这样

String url = "jdbc:mysql://localhost:3306?allowMultiQueries=true";

重新启动,再试试是不是发现没报错了–__–

既然问题解决了,那是不是要学习下allowMultiQueries配置是干啥的呢?

官网解释: click here https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-configuration-properties.html

allowMultiQueries

Allow the use of ‘;’ to delimit multiple queries during one statement (true/false). Default is ‘false’, and it does not affect theaddBatch() and executeBatch() methods, which rely on rewriteBatchStatements instead.

Default: false

Since version: 3.1.1

翻译过来的大概意思是:允许使用;去做批量操作,默认值为false,为默认值时不会影响addBatch() and executeBatch()执行批量,但是动态拼接带;的sql就会不能执行

如果还不能解决你的问题,你可以看看这个:
Jdbc Url 设置allowMultiQueries为true和false时底层处理机制研究

啥?你还想看mysql连接还有哪些配置?那看看这个 jdbc url 配置

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值