Javaee用id怎么实现批量删除
Javaee用id怎么实现批量删除? 谢谢各位了
[解决办法]
DELETE FROM TABLE名 T WHERE T.ID = ''
[解决办法]
public boolean delUser(int[] id) { boolean flag = false; String sql = "delete from userInfo where userId=?"; conn = base.getConnection(); PreparedStatement pst = null; try { pst = conn.prepareStatement(sql); for (int i = 0; i < id.length; i++) { pst.setInt(1, id[i]); // 使用批处理 pst.addBatch(); } // 执行批处理 int[] result = pst.executeBatch(); if (result[0] > 0) { flag = true; } } catch (SQLException e) { e.printStackTrace(); } finally { try { base.free(conn, pst, null); } catch (SQLException e) { e.printStackTrace(); } } return flag; }
[解决办法]