select  * from games where name like '%?%' and type like '%?%' and company like '%?%' and year like '%?%'  
                           pstmt.setString(1, ge.getName());
pstmt.setString(2, ge.getType());
pstmt.setString(3, ge.getCompnay());
pstmt.setString(4, ge.getYear());
                              这样设了四个参数 但是报错 这是一个动态的条件查询语句,你高手帮帮忙

解决方案 »

  1.   

    select * from games where name like '%'+?+'%' 这样看看
      

  2.   

    没明白你的意思,直接string.format不可以?
      

  3.   

    pstmt.setString(4, ge.getYear());ge.getYear是什么类型的 如果不是String类型的 pstmt.setString是错的假如ge.getYear是Long型 那么要这么写pstmt.setLong(4, ge.getYear());检查一个这个匹配是否有误
      

  4.   

    试试这样呢.select * from games where name like ? and type like ? and company like ? and year like ?
    pstmt.setString(1, '%' + ge.getName() + '%');
    pstmt.setString(2, '%' + ge.getType() + '%');
    pstmt.setString(3, '%' + ge.getCompnay() + '%');
    pstmt.setString(4, '%' + ge.getYear() + '%');
      

  5.   

    那你只能是sql按照字符串拼接了