我需要尽快在Tomcat上的HSQLDB中插入1.000.000个条目,但64m(Tomcat上的默认MaxPermSize)对于此代码来说还不够,我得到“OutOfMemoryError”(我想在默认设置中插入)。
connection.setAutoCommit(false);
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO USER (firstName, secondName) VALUES(?,?)");
for (int i = 0; i < 1000000; i++) {
preparedStatement.setString(1, "firstName");
preparedStatement.setString(2, "secondName");
preparedStatement.addBatch();
}
preparedStatement.executeBatch();
connection.commit();
我依旧:http://hsqldb.org/doc/2.0/guide/deployment-chapt.html#dec_bulk_operations。我设置“SET FILES LOG FALSE”但它没有帮助。
答案 0 :(得分:4)
尝试一下,至少会消耗更少的内存:
connection.setAutoCommit(false);
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO USER (firstName, secondName) VALUES(?,?)");
for (int i = 0; i < 1000000; i++) {
preparedStatement.setString(1, "firstName");
preparedStatement.setString(2, "secondName");
preparedStatement.addBatch();
if(i % 1000 == 0)
preparedStatement.executeBatch();
}
preparedStatement.executeBatch();
connection.commit();
编辑:你确定这是因为烫发的大小吗?你能把堆栈跟踪吗?