I want to insert multiple rows into a MySQL table at once using Java. The number of rows is dynamic. I used to do ...
for (String element : array) { myStatement.setString(1, element[0]); myStatement.setString(2, element[1]); myStatement.executeUpdate(); }
I would like to optimize this to use the syntax supported by MySQL:
INSERT INTO table (col1, col2) VALUES ('val1', 'val2'), ('val1', 'val2')[, ...]
but with PreparedStatement I do not know how to do this, because I do not know in advance how many elements the array will contain. If this is not possible with PreparedStatement , how else can I do it (and still avoid the values ββin the array)?
java mysql jdbc prepared-statement
Tom Marthenal Dec 04 '10 at 18:20 2010-12-04 18:20
source share