@Test
public void testInsert() {
Connection con = null;
PreparedStatement ps = null;
try {
con = GetConnection();
String sql = "insert into goods(name) value(?)";
ps = con.prepareStatement(sql);
long start = System.currentTimeMillis();
for (int i = 0; i <= 20000; i++) {
ps.setObject(1,"name" + i);
ps.addBatch();
if (i % 500 == 0){
ps.executeBatch();
ps.clearBatch();
}
}
long end = System.currentTimeMillis();
System.out.println("花费的时间为:" + (end - start));
} catch (Exception e) {
e.printStackTrace();
} finally {
CloseResource(con,ps);
}
}
起初没有使用addBatch、executeBatch方法进行批量插入,使用之后时间也几乎和没使用一样。通过查找资料说是rewriteBatchedStatements没有设置为True,但设置之后并没有任何效果,也有说useServerPrepStmts要设置成false,但也没什么用。
我使用的是8.0.24的,是不是软件包的问题?