通过jdbc连接数据库,批量执行多条SQL语句
方案一Statement ps=conn.createStatement();ps.addBatch("update user set money=money-100 where name='张三'");ps.addBatch("update user set money=money+100 where name='李四'");ps.addBatch("update temp set count=count+1 where name='张三'");ps.executeBatch();不过这种使用的是Statement,只能是使用拼接字符串的方式,来传值;
方案二
如果多条语句重复,只是参数不变的话可以这样
?
PreparedStatement ps=conn.prepareStatement("insert into temp values(?)");方案三
写成存储过程
?