t_a{
id ,
name,
age,
pid,   对应t_b(id) }t_b{
id,
ywlx,
}本人想用
  这种类型的查询
    String sql = "select name,age,ywlx from t_a where 1=1";
    String sql+="(其他的条件补充)";  --其他所需的条件加在这行里面,
         上面的"select name,age,ywlx from t_a where 1=1";语句固定,试问有没有什么好的办法来处理????
   急!!!  在线等。。
   谢谢!!!

解决方案 »

  1.   

     String sql+="(其他的条件补充)";  --其他所需的条件加在这行里面, 
      String sql+="and 条件语句";  --不就OK?
     
      

  2.   

    ywlx这个字段他会报  找不到 的  我第一条sql语句里面就from t_a呀!!!!!!!!!!!!!!!
       有没有其他好的方法
        请教~!!!!
      

  3.   

    String sql = "select name,age,ywlx from t_a where 1=1"; 
        String sql+="(其他的条件补充)";  --其他所需的条件加在这行里面, 
            上面的"select name,age,ywlx from t_a where 1=1";语句固定, 
    那你可以这样子写:String sql = "select name,age,ywlx from t_a,t_b where  t_a.pid=t_b.id and 1=1"; 
    String sql+="and 条件语句";  --不就OK? 
      

  4.   

    oooooooooooooooo
       谢谢了!
         String sql = "select name,age,ywlx from t_a where 1=1";  这条语句固定
       其他条件随便加,  是不是不能做到啊
      

  5.   

    那当然,条件中你想取t_b中的字段,而from 只是t_a中取数据,你说怎么能抓得到!
      

  6.   

    我在DaoImpl里面写
      sql语句我直接通过实体对应的表来查,怎么会报
           org.hibernate.hql.ast.querysyntaxexception:、
      异常?
          可以直接从数据库表来查的呀!!
       怎么回事
      请教一下!