不知道你所谓的多条件查询是什么?
select * from form1,form2 where xxxx=form1.xxxx and wwww=form2.wwww
这也是多条件查询的sql
不知道你想问的是不是这个?

解决方案 »

  1.   

    先在前面把条件处理一下,判断为空的换为'*'select * from employee where (Name='A' or 'A'='*') and (Sex='B' or 'B'='*') and (Age='C' or 'C'='*');你看这样如何?
      

  2.   

    写个类来做查询条件
    public class MyQuery{
        private Map map = new HashMap();
        public void addQuery(String key ,String value){
            //这里存入条件,比如Age,15
            map.put(key,value);
        }
        public String getQueryString(){
            StringBuffer sb = new StringBuffer();
            // 这里把map转换为string,
            // to do
            // 
            return sb.toString();
        }
    }
      

  3.   

    String age = "22";
        String name = "zm";
        String sex = "man";
        String exp = "select * from employee where ";
        if (age.length() >0) {
          exp = exp + "age= " + age + " and ";
        }
        if (name.length() >0) {
          exp = exp + "name='" + name + "' and ";
        }
        if (sex.length() >0) {
          exp = exp + "sex='" + sex + "'";
          //exp.lastIndexOf()
        }
        if(exp.lastIndexOf("and ")==exp.length() -4)
          exp=exp.substring(0,exp.lastIndexOf("and ")) ;    System.out.println(exp);           //test
      

  4.   

    本来的有点问题 条件全没的时候会多个 where
        String age = "22";
        String name = "zm";
        String sex = "man";
        String exp = "select * from employee ";
        String exp1="";
        if (age.length() >0) {
          exp = exp + "age= " + age + " and ";
        }
        if (name.length() >0) {
          exp = exp + "name='" + name + "' and ";
        }
        if (sex.length() >0) {
          exp = exp + "sex='" + sex + "'";
          //exp.lastIndexOf()
        }
        if(exp.lastIndexOf("and ")==exp.length() -4)
          exp=exp.substring(0,exp.lastIndexOf("and ")) ;
        if(exp1.length > 0)           //修改后
          exp=exp+" where "+exp1    System.out.println(exp);           //test
      

  5.   

    public String class find(String name,String ID,String Date)
    {
    String sql="select * from employee where";
    if(name=="")
    sql=sql+"name='"+name+"'";
    if(ID=="")
    sql=sql+"and ID='"+ID+"'";
    if(Date=="")
    sql=sql+"and Date='"+Date+"'";
    if(sql=="select * from employee where")
    sql="select * from employee";
    return sql;
    }
    这样可以解决么?
      

  6.   

    这种部题不会解决???!!!public String findAll(String a,String b,String c)
    {
      select * from 表名 where '"+a+"' '"+b+"' '"+c+"';  
    }然后出JSP 页面里的下拉列表中选择你的任意查询条件