在MySQL中,executeBatch似乎不像事务。
它是否像Redis中的管道一样提高了性能?
更新
这两种用法之间是否有任何性能差异?
一个。的executeUpdate
try (PreparedStatement ps = conn.prepareStatement("INSERT INTO test (key_, value_) VALUES (?, ?)") {
ps.setString(1, "key1");
ps.setString(2, "value1");
ps.executeUpdate();
ps.setString(1, "key2");
ps.setString(2, "value2");
ps.executeUpdate();
}
湾addBatch /则ExecuteBatch
try (PreparedStatement ps = conn.prepareStatement("INSERT INTO test (key_, value_) VALUES (?, ?)")) {
ps.setString(1, "key1");
ps.setString(2, "value1");
ps.addBatch();
ps.setString(1, "key2");
ps.setString(2, "value2");
ps.addBatch();
ps.executeBatch();
}