保利娱乐
您的当前位置:首页PreparedStatement批处理

PreparedStatement批处理

来源:保利娱乐


PreparedStatement批量更新关键代码 无 import java.sql.Connection;import java.sql.PreparedStatement; //...String sql = "insert into employee (name, city, phone) values (?, ?, ?)";Connection connection = new getConnection();PreparedStatement p

PreparedStatement批量更新关键代码 <无> $velocityCount-->
import java.sql.Connection;
import java.sql.PreparedStatement;
 //...
String sql = "insert into employee (name, city, phone) values (?, ?, ?)";
Connection connection = new getConnection();
PreparedStatement ps = connection.prepareStatement(sql);
 for (Employee employee: employees) {
 ps.setString(1, employee.getName());
 ps.setString(2, employee.getCity());
 ps.setString(3, employee.getPhone());
 ps.addBatch();
}
ps.executeBatch();
ps.close();
connection.close();
显示全文