第一次奇怪的JSP删除数据库记录问题,执行删除语句ResultSet就为空
以下是本人的代码,从另一个页面表单提交获得选中的复选框的值,若选中获得对应的id值
删除id对应的记录
<%
int count=newsPage.getCurrentPageSize(); //当页复选框数目
ArrayList <Integer> IDS=new ArrayList <Integer> ();
for(int i=0;i <count;i++)
{
int num=i+1;
String value=request.getParameter(String.valueOf(num));//得到复选框的值
if(value!=null&&value.toLowerCase().equals( "on "))
{
int id=Integer.parseInt(request.getParameter( "checkBox "+num));
IDS.add(new Integer(id));
}
}
Connection con=db.getConnection();
int j=0;
if(con!=null)
{
String sql= "DELETE FROM NEWS WHERE ";
Statement sta1=null;
PreparedStatement sta2=null;
try
{
sta1=con.createStatement();
sta2=con.prepareStatement( "SELECT * FROM NEWS WHERE ID=? ");
for(int i=0;i <IDS.size();i++)
{
try
{
int ID=IDS.get(i);
out.print(ID);
if(i!=0)
sql+= " OR ID= "+ID;
else
sql+= " ID= "+ID;
sta2.setInt(1,ID);
ResultSet set=sta2.executeQuery();
if(set.next())
{
out.print( "true ");
}
}
catch(Exception e)
{
e.printStackTrace();
}
j++;
}
sta1.executeUpdate(sql);
sta1.close();
sta2.close();
con.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
%>
结果只是 1 2 3 4 5 6
若去掉
sta1.executeUpdate(sql);
结果才是1true 2true 3true 4true 5true 6true
希望能人相助,在下感激不尽,立即给分100
[解决办法]
是在一次事务里面执行的 不是每次都提交
[解决办法]
大哥,你别吓我啊,有这样的结果
[解决办法]
学习一下
[解决办法]
String [] value = request.getParameterValues( "checkbox ");//获得选中的id值,
把它再转成个字符串,比如1,2,3 然后直接delete from table where id in 字符串