// insert
time = System.currentTimeMillis();
stat.execute("DROP TABLE IF EXISTS TEST");
trace("drop=" + (System.currentTimeMillis() - time));
stat.execute("CREATE CACHED TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))");
PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST VALUES(?, 'Hello World')");
printTimeMemory("start", 0);
time = System.currentTimeMillis();
for (int i = 0; i < len; i++) {
prep.setInt(1, i);
prep.execute();
if (i % 50000 == 0) {
trace(" " + (100 * i / len) + "%");
}
}
printTimeMemory("insert", System.currentTimeMillis() - time);
// update
time = System.currentTimeMillis();
prep = conn.prepareStatement("UPDATE TEST SET NAME='Hallo Welt' || ID WHERE ID = ?");
for (int i = 0; i < len; i++) {
prep.setInt(1, i);
prep.execute();
if (i % 50000 == 0) {
trace(" " + (100 * i / len) + "%");
}
}
printTimeMemory("update", System.currentTimeMillis() - time);
// select
time = System.currentTimeMillis();
prep = conn.prepareStatement("SELECT * FROM TEST WHERE ID = ?");
for (int i = 0; i < len; i++) {
prep.setInt(1, i);
ResultSet rs = prep.executeQuery();
rs.next();
assertFalse(rs.next());
if (i % 50000 == 0) {
trace(" " + (100 * i / len) + "%");
}
}
printTimeMemory("select", System.currentTimeMillis() - time);
// select randomized
Random random = new Random(1);
time = System.currentTimeMillis();
prep = conn.prepareStatement("SELECT * FROM TEST WHERE ID = ?");
for (int i = 0; i < len; i++) {
prep.setInt(1, random.nextInt(len));
ResultSet rs = prep.executeQuery();
rs.next();
assertFalse(rs.next());
if (i % 50000 == 0) {
trace(" " + (100 * i / len) + "%");
}
}
printTimeMemory("select randomized", System.currentTimeMillis() - time);
// delete
time = System.currentTimeMillis();
prep = conn.prepareStatement("DELETE FROM TEST WHERE ID = ?");
for (int i = 0; i < len; i++) {
prep.setInt(1, random.nextInt(len));
prep.executeUpdate();
if (i % 50000 == 0) {
trace(" " + (100 * i / len) + "%");
}
}
printTimeMemory("delete", System.currentTimeMillis() - time);