簡體   English   中英

MySQL prepareStatement 批處理速度慢

[英]MySQL prepareStatement Batch slow

我有以下代碼在 MySQL 表中插入行:

String sqlInsert = "INSERT INTO test_perf_table ( id, name) VALUES ( ?, ?);";
PreparedStatement sqlInsertSt = connection.prepareStatement(sqlInsert);

for (int i = 0; i < SETSIZE; i++) {
    sqlInsertSt.setInt( 1, ids[i]);
    sqlInsertSt.setString( 2, names[i]);
    sqlInsertSt.addBatch();
}
int[] updateCounts = sqlInsertSt.executeBatch();

問題是我每秒只歸檔 21 筆交易,這真的很低,期望速度提高 10 倍。

所以我的問題是,我的代碼需要改進還是數據庫配置問題?

MySQL 服務器在 Win8 中運行 @localhost,使用 my-large.ini 默認配置,使用 mysql-connector-java-5.1.13 驅動程序。

不確定,但我認為引擎是 myisam,因為我沒有指定任何內容

編輯:

CREATE TABLE test_perf_table (
    id INT,
    name VARCHAR(20) 
);

我最近剛處理過這個。

最大的不同是將參數rewriteBatchedStatements=true添加到您的 jdbc 連接 url。

您還可以通過在事務中執行 executeBatch() 來看到性能改進。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM