使用JDBC连接MySQL数据库进行数据插入的时候,特别是大批量数据连续插入(10W+),如何提高效率呢? 在JDBC编程接口中Statement 有两个方法特别值得注意: void addBatch() throws SQLException Adds a set of parameters to this PreparedStatement object's batch of commands. int[] executeBatch() throws SQLException Submits
最近迷上一种批量插入的方法,一句sql解决,将需要插入的数据用with as 的方式查出来,不管多么复杂的sql,都可以用临时表的方式查出来,然后直接插入,这样代码更加清晰 流程也简单 insert into 表1 with t1 as (select * from 表2), t2 as (select * from t1 inner join 表2 on t1.qw = 表2.qw)select * from t2; 这么写的话就是插入表1的数据用with as全部临时查出来.