java实现批量更新数据_java批量更新数据库

String [] queries = {

"INSERT INTO Employee { Eno, Ename, Ecode, EDept} values ('1', 'Allen', 'abc', 'Sales')",

"INSERT INTO Employee { Eno, Ename, Ecode, EDept} values ('2', 'Max', '102', 'Marketing')",

"INSERT INTO Employee { Eno, Ename, Ecode, EDept} values ('3', 'Ward', 'xyz', 'Sales')",

"INSERT INTO Employee { Eno, Ename, Ecode, EDept} values ('4', 'Sam', '55', 'Marketing')",

};

Connection connection = new getConnection();

Statement statement = connection.createStatement();

for (String query : queries ) {

statement.execute(query);

}

statement.close();

connection.close();

这是一个糟糕的代码,在数据库中每一行INSERT语句都需要单独来执行。发送一批INSERT语句到数据库中一气呵成:

你可能感兴趣的:(java实现批量更新数据)