我想使用Java一次将多行插入MySQL表.行数是动态的.过去我在做......
for (String element : array) {
myStatement.setString(1, element[0]);
myStatement.setString(2, element[1]);
myStatement.executeUpdate();
}
Run Code Online (Sandbox Code Playgroud)
我想优化它以使用MySQL支持的语法:
INSERT INTO table (col1, col2) VALUES ('val1', 'val2'), ('val1', 'val2')[, ...]
Run Code Online (Sandbox Code Playgroud)
但是PreparedStatement我不知道有什么方法可以做到这一点,因为我事先不知道array会包含多少元素.如果a不可能PreparedStatement,我还能怎么做(并且仍然逃避数组中的值)?