一次性执行多条语句

项目中有很多小问题需要解决。一个是获取自动增长的数据。今天又解决了一个小问题。

就是在sql语句中若同时执行多条语句。我们是这样写的

insert into  table1(name) values ('name');insert into table2(ID,group) values()

可是在作为一条语句执行时报错

check the manual that corresponds to your MySQL server version for the right….

解决办法如下

1、在MySQL的连接字符串中设置allowMultiQueries=true。
2、在程序中对SQL语句以分号拆分成多条SQL语句,然后使用Statement的addBatch方法,最后executeBatch就行。

希望给搜到这个问题的童鞋帮助

Leave a Reply

Your email address will not be published. Required fields are marked *