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;
  • 相关阅读:
    Cookies
    一个完整的upstart脚本分析
    squid总结
    python递归读取目录列表
    python删除文件
    ubuntu切割mp3文件
    TP-LINK TL-WN725N V2 / rtl8188eu Linux驱动安装
    ubuntu启动脚本
    su对环境变量做了什么
    sudoers文件配置
  • 原文地址:https://www.cnblogs.com/zwl24/p/2543458.html
Copyright © 2011-2022 走看看