zoukankan      html  css  js  c++  java
  • 关于SQL语句的拼接问题

    1 public List<PostVo> queryByKeyWord(String keyWord){
    2         BeanListHandler<PostVo> bh=new BeanListHandler<PostVo>(PostVo.class);
    3         List<PostVo> list=jt.query("select * from post where title like '%?%' or author like '%?%' or content like '%?%'  order by noteid ", bh,keyWord,keyWord,keyWord);
    5         jt.close();
    6         return list;
    }


    死活查不到数据,原因是SQL代码拼接总会有点问题,记得以前做PHP时也出现过这种情况。

    改成下面的就可以了。

    1 public List<PostVo> queryByKeyWord(String keyWord){
    2         BeanListHandler<PostVo> bh=new BeanListHandler<PostVo>(PostVo.class);
    3         String param="%"+keyWord+"%";
    4         List<PostVo> list=jt.query("select * from post where title like ? or author like ? or content like ?  order by noteid ", bh,param,param,param);
    5         jt.close();
    6         return list;
  • 相关阅读:
    eclipse
    ORA00904:标识符无效,preparedstatement
    mysql 创建用户
    web 默认servlet
    https tomat
    gzip
    sftp 上传文件
    jquery dwrutil confilit
    xmlbeans读写xml文件
    敏捷开发“松结对编程”实践大型团队篇
  • 原文地址:https://www.cnblogs.com/zwl24/p/2543458.html
Copyright © 2011-2022 走看看