我有下面的代碼在一個MySQL表中插入行:MySQL的prepareStatement批緩慢
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)
);
「SHOW CREATE TABLE」如何顯示,這可能會顯示一些重要的細節。另外,是不是你的'for'循環每次都會覆蓋參數? –
沒有每個循環向批處理添加一個語句,如果我沒有錯 – fxe