81,095
社区成员
发帖
与我相关
我的任务
分享
String sqlstr = "select * from Table where ";
int a = Integer.parseInt(request.getParameter("a"));
int b = Integer.parseInt(request.getParameter("b"));
int c = Integer.parseInt(request.getParameter("c"));
int d = Integer.parseInt(request.getParameter("d"));
if (a!= -1)
sqlstr = sqlstr + " a=" + a;
if (b != -1)
sqlstr = sqlstr + " and b=" + b;
if (c != -1)
sqlstr = sqlstr + " and c=" + c;
if (d!= -1)
sqlstr = sqlstr + " and d=" + d;
String temp = "";
if (a!= -1)
temp = temp + " a=" + a;
if (b != -1) {
if (temp.length > 0) {temp = temp + " and";}
temp = temp + " b=" + b;
}
if (c != -1) {
if (temp.length > 0) {temp = temp + " and";}
temp = temp + " c=" + c;
}
if (d!= -1) {
if (temp.length > 0) {temp = temp + " and";}
temp = temp + " d=" + d;
}
sqlstr = sqlstr + temp