JAVA中删除数据库数据,根据数组删除,怎么写。 方法:public void delete(int[] ids) {
2个回答
展开全部
public void delete(int[] id) throws SQLException{
//假定conn ps 都获取到
Connection conn=null;
StringBuffer sql=new StringBuffer("delete from school where id in(");
for (int i = 0; i < id.length; i++) {
if (i==id.length-1)
sql.append(id[i]+")");
else
sql.append(id[i]+",");
}
PreparedStatement ps=conn.prepareStatement(sql.toString());
ps.execute();
}
//假定conn ps 都获取到
Connection conn=null;
StringBuffer sql=new StringBuffer("delete from school where id in(");
for (int i = 0; i < id.length; i++) {
if (i==id.length-1)
sql.append(id[i]+")");
else
sql.append(id[i]+",");
}
PreparedStatement ps=conn.prepareStatement(sql.toString());
ps.execute();
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询