一条语句删除全选:
1、转化数组
StringBuilder sbStr = new StringBuilder();
for (int i=0; i<userIds.length; i++) {
sbStr.append("?");
if (i < (userIds.length - 1)) {
sbStr.append(",");
}
}
2、编写sql
String sql = "delete from t_user where user_id in (" + sbStr.toString() + ")";
3、设置占位符
PrepareStatement pstmt = conn.prepareStatement(sql);
for (int i=0; i<userIds.length; i++) {
pstmt.setString(i + 1, userIds[i]);
}
pstmt.executeUpdate();
1、转化数组
StringBuilder sbStr = new StringBuilder();
for (int i=0; i<userIds.length; i++) {
sbStr.append("?");
if (i < (userIds.length - 1)) {
sbStr.append(",");
}
}
2、编写sql
String sql = "delete from t_user where user_id in (" + sbStr.toString() + ")";
3、设置占位符
PrepareStatement pstmt = conn.prepareStatement(sql);
for (int i=0; i<userIds.length; i++) {
pstmt.setString(i + 1, userIds[i]);
}
pstmt.executeUpdate();