日期:2014-05-17  浏览次数:20598 次

jsp制作搜索模块出现很奇怪的问题,求大神帮忙!!
jsp制作搜索模块出现很奇怪的问题:
  比如有一篇文章 :你好漂亮漂亮
  在输入框输入关键字 “你” 可以查到这篇文章 可是输入 “漂” 或者输入 “漂亮” 或者输入 “你好” 都无法查找到这篇文章 求大神帮忙!!
  部分代码如下:
  public List<Boke> queryByLike(String keyword,int PageNow) throws Exception { //关键字查询,模糊查询
int Size = 6 ; //每页显示的数量
int BeginIndex = PageNow*(Size-1) + 1 ;  
int EndIndex = PageNow*(Size-1) + 6 ;
String KeyWord = "%" + keyword + "%" ;

DataBaseConnection dbc = new DataBaseConnection();
List<Boke> ls = new ArrayList<Boke>();
String sql = "select boke_id,boke_title,boke_author,boke_time,boke_content,boke_hit,boke_type, boke_reprint,boke_pl from boke where boke_title like ? order by boke_id desc limit ?,?" ;
PreparedStatement pstmt = null;
try {
pstmt = dbc.getConnection().prepareStatement(sql);
pstmt.setString(1,KeyWord);
pstmt.setInt(2,BeginIndex);
pstmt.setInt(3,EndIndex);
ResultSet rs = pstmt.executeQuery();

------解决方案--------------------
sql语句改下:String sql = "select boke_id,boke_title,boke_author,boke_time,boke_content,boke_hit,boke_type, boke_reprint,boke_pl from boke where boke_title like %?% order by boke_id desc limit ?,?" ;

------解决方案--------------------
大哥你 like ?就是第一个字符要对 所有只有第一个对才可以 你改成%?%就是包含这个?号的字符了 不管是在前面还是中间还是后面