Hi Brish,
> I tried it a while ago. Batch updates against an h2 server were
> significantly slower than running the statements one at a time.
> I don't know if it's still true.
According to my test there is no difference any longer.
batch: false time: 39344
batch: true time: 36860
batch: false time: 42062
batch: true time: 37938
batch: false time: 41078
batch: true time: 35610
batch: false time: 38844
batch: true time: 38078
Sometimes batch is faster, sometimes non-batch.
Regards,
Thomas
public static void main(String[] args) throws Exception {
Class.forName("org.h2.Driver");
for (int k = 0; k < 8; k++) {
DeleteDbFiles.execute(null, "test", true);
Connection conn = DriverManager.getConnection("jdbc:h2:test");
boolean batch = k % 2 == 1;
Statement stat = conn.createStatement();
stat.execute("create table test(id identity, name varchar)");
PreparedStatement prep = conn.prepareStatement("insert
into test(name) values(?)");
long time = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
prep.setString(1, "Hello");
if (batch) {
prep.addBatch();
if (i % 1000 == 0) {
prep.executeBatch();
}
} else {
prep.execute();
}
}
if (batch) {
prep.executeBatch();
}
System.out.println("batch: " + batch + " time: " +
(System.currentTimeMillis() - time));
conn.close();
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en
-~----------~----~----~----~------~----~------~--~---