在java中使用jdbc驱动程序的慢sqlite插入 [英] slow sqlite insert using the jdbc drivers in java
问题描述
我刚将1百万条记录插入到一个包含五列的简单sqlite表中。使用jdbc驱动程序在java中花了18个小时!我在python2.5中做了同样的事情,花了不到一分钟。选择查询的速度似乎很好。我认为这是jdbc驱动程序的问题。
I just inserted 1million records into a simple sqlite table with five columns. It took a whooping 18 hours in java using the jdbc drivers! I did the same thing in python2.5 and it took less than a minute. The speed for select queries seem fine. I think this is an issue with the jdbc drivers.
java中有没有更快的sqlite3驱动程序?
Is there a faster driver for sqlite3 in java?
插入大量行的速度对于我的架构迁移脚本非常重要,如果我不这样做,我宁愿不必使用外部脚本来执行迁移。必须。
Speed of inserting large numbers of rows is important for my schema migration script, and I'd rather not have to use an external script to do the migrations if I don't have to.
编辑:用connection.setAutoCommit(false)修复;
感谢Mark Rushakoff向我暗示解决方案:)
fixed with connection.setAutoCommit(false); thanks Mark Rushakoff for hinting me to the solution :)
推荐答案
您是否自动提交了查询?这可以解释为什么花了这么长时间。尝试将它们包装在开头/结尾,这样就不必为每个插件执行完整的提交。
Did you have your queries autocommitted? That could explain why it took so long. Try wrapping them in a begin / end so that it doesn't have to do a full commit for every insert.
This page explains begin/end transaction, while the FAQ touches on inserts/autocommits.
这篇关于在java中使用jdbc驱动程序的慢sqlite插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!