使 JDBC 插入查询更快

Making JDBC insert query faster

我正在从主 table(oracle) 获取数据,并不断将其添加到实体列表,直到获取全部数据。 master table 有 45 列。然后我遍历列表并将每一行插入我的本地 table(oracle)。

本地 table 的架构与原始 table 不完全相同。 localtable中有3个额外的列,其中的数据仅从其他列处理。因此,在处理完整行后,将添加到本地 table.

插入查询花费了大量时间,即使我还没有在 table 上创建索引。如何使插入更快?

使用一批插入。像这样:

Connection connection = new getConnection();
Statement statement = connection.createStatement();

for (String query : queries) {
    statement.addBatch(query);
}
statement.executeBatch();
statement.close();
connection.close();

在此处查看完整示例:http://viralpatel.net/blogs/batch-insert-in-java-jdbc/