Questions tagged «batch-insert»

6
Java:使用PreparedStatement将多行插入MySQL
我想使用Java一次在MySQL表中插入多行。行数是动态的。过去我在做... for (String element : array) { myStatement.setString(1, element[0]); myStatement.setString(2, element[1]); myStatement.executeUpdate(); } 我想对此进行优化,以使用MySQL支持的语法: INSERT INTO table (col1, col2) VALUES ('val1', 'val2'), ('val1', 'val2')[, ...] 但由于PreparedStatement我不知道有什么方法可以这样做,因为我事先不知道array将包含多少个元素。如果无法使用PreparedStatement,我该怎么办(仍然对数组中的值进行转义)?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.