我用的是java jdbc的addBatch批量插入数据,但是速度好慢有什么好的方案吗
差不多插入1000条数据需要30s,下面贴出代码大家看看哪里不规范,或者给个更快的方法
//jdbc构造的URL是 private static final String URL="jdbc:mysql://localhost:3306/daan?useUnicode=true&characterEncoding=UTF8&rewriteBatchedStatements=true";
public static void writeData(LinkedListentities) { con = DBUtil.getCon(); String sql = "INSERT INTO `test` (`title`,`url`,`year`,`grade`,`subject`,`publish`) VALUES (?,?,?,?,?,?)"; try { PreparedStatement preparedStatement = con.prepareStatement(sql); for (int i = 0;i
你在这执行完preparedStatement.addBatch()后直接调用了preparedStatement.execute();这样操作就相当于一次插入一条数据,你可以在循环每1000次之后调用preparedStatement.executeBatch();
JDBC BATCH INSERT.