java 在java中PreparedStatement.addBatch有什么限制吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4392091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PreparedStatement.addBatch in java has any restrictions?
提问by adiian
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.
我正在尝试优化将大量结果插入远程 mySQL 数据库的过程。我为此使用了简单的 jdbc。
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.
目前我正在用 PreparedStatement 替换退出语句,并用 addBatch/executeBatch 方法执行方法。有谁知道批处理执行的限制是什么?在执行之前我可以添加多少批次以确保流程不会失败?查询不是特殊查询,它们没有 blob 或其他大字段。
采纳答案by Joshua Martell
@BalusC hit the nail on the head. If you're using MySQL, use the latest driver add rewriteBatchedStatements=trueto your connection string to make statement.addBatch() actually create batch inserts.
@BalusC 一针见血。如果您使用的是 MySQL,请使用最新的驱动程序将rewriteBatchedStatements=true添加到您的连接字符串中,以使 statement.addBatch() 实际创建批量插入。
Nice presentation on MySQL JDBC performance: http://assets.en.oreilly.com/1/event/21/Connector_J%20Performance%20Gems%20Presentation.pdf
关于 MySQL JDBC 性能的精彩演示:http: //assets.en.oreilly.com/1/event/21/Connector_J%20Performance%20Gems%20Presentation.pdf