I have the following code to insert rows in a MySQL table:
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();
The problem is i am only archiving 21 transactions per second which is really low, was expecting something 10x faster.
So my question is, does my code need to improved or maybe is the database configuration problem ?
The MySQL server is running @localhost, in Win8, using the my-large.ini default config, using mysql-connector-java-5.1.13 driver.
Not sure but i think the engine is myisam since i did not specify anything
edit:
CREATE TABLE test_perf_table (
id INT,
name VARCHAR(20)
);
I just dealt with this recently.
The thing that will make the biggest difference is adding the parameter
rewriteBatchedStatements=trueto your jdbc connection url.You may also see a performance improvement by executing executeBatch() in a transaction.