java中的PreparedStatement.addBatch有什么限制吗? [英] PreparedStatement.addBatch in java has any restrictions?
问题描述
我正在尝试优化将大量结果插入远程mySQL数据库的过程。我正在使用简单的jdbc。
I'm trying to optimize the process of inserting a large number of results to a remote mySQL database. I'm using simple jdbc for that.
目前我正在用PreparedStatement替换exiting语句,并使用addBatch / executeBatch方法执行方法。有谁知道批量执行的限制是什么?我可以在执行前添加多少批,以确保流程不会失败?查询不是特殊查询,它们没有blob或其他大字段。
Currently I'm replacing exiting statements with PreparedStatement and execute methods with addBatch/executeBatch methods. Does anyone know which are the limits of a batch execution? How many batches can I add before execution to make sure the process doesn't fail? The queries are not special queries, they don't have blobs or other large fields.
推荐答案
@BalusC打了钉子头。如果您正在使用MySQL,请使用最新的驱动程序将 rewriteBatchedStatements = true 添加到您的连接字符串中,以使statement.addBatch()实际创建批量插入。
@BalusC hit the nail on the head. If you're using MySQL, use the latest driver add rewriteBatchedStatements=true to your connection string to make statement.addBatch() actually create batch inserts.
关于MySQL JDBC性能的精彩演示:
http://assets.en.oreilly.com/1/event/21/Connector_J%20Performance%20Gems%20Presentation.pdf
Nice presentation on MySQL JDBC performance: http://assets.en.oreilly.com/1/event/21/Connector_J%20Performance%20Gems%20Presentation.pdf
这篇关于java中的PreparedStatement.addBatch有什么限制吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!