1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| @Test public void test3() throws Exception { Connection conn = JDBCUtils.getConnection(); String sql = "insert into goods(name) values(?)"; PreparedStatement ps = conn.prepareStatement(sql); conn.setAutoCommit(false); long start = System.currentTimeMillis(); for (int i = 0; i < 1000; i++) { ps.setObject(1, "name" + i); ps.addBatch(); if (i % 500 == 0){ ps.executeBatch(); ps.clearBatch(); } } conn.commit(); long end = System.currentTimeMillis(); System.out.println("花费时间为:" + (end-start)); JDBCUtils.close(conn, ps); }
|