batch-insert

Java: Insert multiple rows into MySQL with PreparedStatement

邮差的信 提交于 2019-11-26 03:17:25
问题 I want to insert multiple rows into a MySQL table at once using Java. The number of rows is dynamic. In the past I was doing... for (String element : array) { myStatement.setString(1, element[0]); myStatement.setString(2, element[1]); myStatement.executeUpdate(); } I\'d like to optimize this to use the MySQL-supported syntax: INSERT INTO table (col1, col2) VALUES (\'val1\', \'val2\'), (\'val1\', \'val2\')[, ...] but with a PreparedStatement I don\'t know of any way to do this since I don\'t