81,092
社区成员
发帖
与我相关
我的任务
分享
public void executeBatch() throws Exception {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection("jdbc:sqlserver://127.0.0.1:1433;DatabaseName=CowainDB;userName=CMW;password=Cek50170270");
String sql="insert into PurchasingThemThe values(?,?,?,?,?,?,?,?,?)";
PreparedStatement sta = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
List<RecordVo> list = xxxx;// 这根据你以前传给addPurchasingThemThe的参数可以得到。
addPurchasingThemThe(List<RecordVo> list, PreparedStatement sta); // 可以实现批量录入
if (con != null) {
con.close();
con = null;
}
}
public boolean addPurchasingThemThe(List<RecordVo> list, PreparedStatement sta) throws Exception {
for (RecordVo vo : list) {
sta.setString(1, vo.getImpttGRNNumber());
// ......
sta.addBatch();
}
sta.executeBatch();
if (sta != null) {
sta.close();
sta = null;
}
}