【已解决】在使用mybatis的时候,怎么一次删除多个表

  • 作者: 凯哥Java(公众号:凯哥Java)
  • 工作小总结
  • 时间:2023-01-12 15:47
  • 3678人已阅读
简介 在我们工作的时候,有时候,会遇到这种情况,比如删除数据的时候,既要删除数据本身,也要删除数据对应log日志表中的数据,那么,使用mybatis怎么在一个deleteid中删除多个呢?如下图:如果直接按照上面这样写,可能会出现问题。###Errorupdatingdatabase. Cause:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxError

🔔🔔好消息!好消息!🔔🔔

 如果您需要注册ChatGPT,想要升级ChatGPT4。凯哥可以代注册ChatGPT账号代升级ChatGPT4

有需要的朋友👉:微信号 kaigejava2022

在我们工作的时候,有时候,会遇到这种情况,比如删除数据的时候,既要删除数据本身,也要删除数据对应log日志表中的数据,那么,使用mybatis怎么在一个delete id中删除多个呢?

如下图:

ee202fef82dd5932ac546817390ebd00.png

如果直接按照上面这样写,可能会出现问题。


### Error updating database.  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 'delete from tbl_article where id = 1248' at line 2

### The error may involve com.lxinet.jeesns.modules.cms.dao.IArticleDao.delete-Inline

### The error occurred while setting parameters

### SQL: delete from tbl_action_log where type=1 and foreign_id = ?;     delete from tbl_article where id = ?

### 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 'delete from tbl_article where id = 1248' at line 2

; bad SQL grammar []


解决办法:

在数据库的链接上,加入允许批量操作的。否则会报错。

jdbc:mysql://localhost:3306/数据库名称?characterEncoding=utf8&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false&&allowMultiQueries=true

其中的&allowMultiQueries=true 一定要加上。否则执行不了。


============ 凯哥的数据库乱码,添加这个也好了========

因为之前,凯哥的数据库连接是带有这个参数的,可能是某次不小心,改丢了。导致乱码

TopTop