拼装sql!
sql_education=" education= '" + education +"' ";
sql_location=" and location= '" + location+"' ";
................
最后sql= "select ID,.........from Position where " + sql_education + sql_location + ....

解决方案 »

  1.   

    哦,忘了说了,生成sql_education、sql_location、...时,之前要判断一下!
    if(education.equals(""))
    sql_education="";
    else
    sql_education=" education= '" + education +"' ";如此类推...
      

  2.   

    这样写
    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+"'";
    }这样就没有问题了
      

  3.   

    最后忘了写
    query=query+str;
      

  4.   

    如果你未选参数,那么传过来的就是空值了,条件就变成这样了where education='' 或
    where education='null',当然查不到你要的值,再说,你传过来的参数需要进行空值处理(建议写一个通用函数,可以提高代码的重用性,省很多事哦),如果需要用到模糊查询的话,就直接用like吧
    public static String getStr(String con){
     return con==null?"":con; 
    }
    然后处理参数时用where education='"+getStr(education)+"'",就方便多了
      

  5.   

    恩对用判断没个下拉筐.
    你可以先把option 设置成"请选择"
    然后用if(!education.equals("请选择"))就可以~~~如果等于就不行啊