我正在尝试提高Java应用程序的性能,并且我将重点放在一个端点上,该端点必须向mysql中插入大量数据.
我在MariaDB Java客户端驱动程序中使用纯JDBC:
try (PreparedStatement stmt = connection.prepareStatement(
"INSERT INTO data (" +
"fId, valueDate, value, modifiedDate" +
") VALUES (?,?,?,?)") {
for (DataPoint dp : datapoints) {
stmt.setLong(1, fId);
stmt.setDate(2, new java.sql.Date(dp.getDate().getTime()));
stmt.setDouble(3, dp.getValue());
stmt.setDate(4, new java.sql.Date(modifiedDate.getTime()));
stmt.addBatch();
}
int[] results = statement.executeBatch();
}
通过从转储文件填充新的数据库,我知道max_allowed_packet很重要,我已将其设置为536,870,912字节.
If you are inserting many rows from the same client at the same time,
use INSERT statements with multiple VALUES lists to insert several
rows at a time. This is considerably f