拼装sql!
sql_education=" education= '" + education +"' ";
sql_location=" and location= '" + location+"' ";
................
最后sql= "select ID,.........from Position where " + sql_education + sql_location + ....
sql_education=" education= '" + education +"' ";
sql_location=" and location= '" + location+"' ";
................
最后sql= "select ID,.........from Position where " + sql_education + sql_location + ....
if(education.equals(""))
sql_education="";
else
sql_education=" education= '" + education +"' ";如此类推...
String query="select ID,.........from Position where 1=1 "
if(!education.equals(""))
{
str=" and education='"+education+"'";
}
if(!location.equals(""))
{
str=str+" and location='"+location+"'";
}
if(!totaltime.equals(""))
{
str=str+" and totalTime='"+totalTime+"'";
}
if(!salary.equals(""))
{
str=str+"and salary='"+salary+"'";
}这样就没有问题了
query=query+str;
where education='null',当然查不到你要的值,再说,你传过来的参数需要进行空值处理(建议写一个通用函数,可以提高代码的重用性,省很多事哦),如果需要用到模糊查询的话,就直接用like吧
public static String getStr(String con){
return con==null?"":con;
}
然后处理参数时用where education='"+getStr(education)+"'",就方便多了
你可以先把option 设置成"请选择"
然后用if(!education.equals("请选择"))就可以~~~如果等于就不行啊