zhangjingl02 / activejdbc

Automatically exported from code.google.com/p/activejdbc
0 stars 0 forks source link

multi insert/update in fast batch #177

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When must insert a lot of record, it will be good to make this in batch.
In normal JDBC it is done by this code fragment:

        PreparedStatement  ps = c.prepareStatement("INSERT INTO ACCOUNTS (BID,AID,ABALANCE)"+
        "VALUES(?,?,0)");
        for(int i=oldscalefactor*100000+1;i<=newscalefactor*100000;) {
                for(int j=0;j<1000;j++,i++){
                        ps.setInt(1, 1+(i-1)/100000);
                        ps.setInt(2, i);
                        ps.addBatch();
                }

                ps.executeBatch();
                c.commit();
                ps.clearBatch(); 
        }

Original issue reported on code.google.com by g.annunziata@gmail.com on 27 Sep 2012 at 1:29