67,513
社区成员
发帖
与我相关
我的任务
分享
批量删除数据
PreparedStatement pstmt = null;
String sql = "update table set column1=XXX where column=?";
try {
pstmt = conn.prepareStatement(sql);
int count = 0;
for (int i = 0; i < values.length; i++) {
pstmt.setString(1, var1);
pstmt.addBatch();
count++;
if (count % 1000 == 0) {
pstmt.executeBatch();
pstmt.clearBatch();
count = 0;
}
}
if (count > 0) {
pstmt.executeBatch();
pstmt.clearBatch();
}
pstmt.close();
} catch (Exception e) {
throw e;
} finally {
if (pstmt != null) {
pstmt.close();
}
if (conn != null)
conn.close();
}