JAVA批量删除问题

为什么通过参数传递进去不行呢?StringBufferstrPrame=newStringBuffer();for(inti=0;i<userCodeList.lengt... 为什么通过参数传递进去不行呢?
StringBuffer strPrame = new StringBuffer();
for (int i = 0; i < userCodeList.length; i++) {
strPrame.append("'");
strPrame.append(userCodeList[i]);
strPrame.append("'");
strPrame.append(",");
}

String sql = "DELETE FROM Users WHERE userCode IN (?)";

PreparedStatement pstmt = null;
try {
pstmt = con.prepareStatement(sql);
String Prames = strPrame.substring(0, strPrame.length() - 1);
pstmt.setString(1, Prames);
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}

用拼接字符串倒是可以,用穿参删除失败,是哪点错了?
展开
 我来答
244371228
2009-07-12 · TA获得超过723个赞
知道小有建树答主
回答量:1435
采纳率:100%
帮助的人:604万
展开全部
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;
}

只能这样来进行批量删除 好好的看一下
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式