Java – JDBC batch execution is extremely slow

Anyone can tell me what I did wrong. I execute 350 plug-ins in MySQL and it takes 40 seconds

This is the code

long t0 = System.currentTimeMillis();
        Connection con = connectionProvider.getConnection();
        PreparedStatement s = con.prepareStatement("insert into domkee.friends(idFriends,friend1Id,friend2Id,friend2Name) values(?,?,?)");
        con.setAutoCommit(false);
        for (Friend f : friends) {
            s.setLong(1,0);
            s.setLong(2,f.getFriend1Id());
            s.setLong(3,f.getFriend2Id());
            s.setString(4,f.getFriend2Name());
            s.addBatch();

        }
        long t1 = System.currentTimeMillis() - t0;
        s.executeBatch();
        long t2 = System.currentTimeMillis()-t0;
        con.commit();
        long t3 = System.currentTimeMillis()-t0;
        s.close();
        con.close();
        long t4 = System.currentTimeMillis()-t0;
        System.out.println(((double)t1/1000) + ";" + ((double)t2/1000) + ";" + ((double)t3/1000) + ";" + ((double)t4/1000));

This is the console:

0.156;39.251;39.376;39.486

So Executebatch() took 40 seconds. What might be the problem?

Solution

Will? Rewritebackedstatements = true is added to the end of the JDBC URL It will give you a serious performance improvement Note that this is @ r specific_ 502_ 1638 @ will not have any impact on any other JDBC drivers

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>