日期:2014-05-20  浏览次数:20780 次

字符串的“乘法”--非类型转换
Java code

String[] chkId = request.getParameterValues("projectId");
String sql = "delete from t_student where checkbox=?";
String sql2 = " or checkbox=?";

Connection conn = ....;
PreparedStatement pstmt = ....;
pstmt = conn.prepareStatement(sql);
for(int i=0;i<chkId.length;i++){
   //假想的实现功能      
   sql = sql + sql2*(chkId.length-1);
}


SERVLET请求值可能有多个,同时请求到得的值作为数据库一个表中的列。
从数据库删除这几列
Java code

delete from t_student where checkbox =? or checkbox=? or checkbox=?......


请问在FOR循环初应该怎么办。。或者有更好的解决方法?


------解决方案--------------------
直接拼就好了撒
Java code

String sql = "delete from t_student where 1=1";
String condition = "AND checkbok in (";
for(int i=0;i<chkId.length;i++){
    condition += "?,"
}
condition = condition.subString(0, condition.length() - 1);
condition += ")"