做模糊搜索时,出现了 bind or column index out of range: handle 0x2fb180 报错
public Cursor getTitle(String word) throws SQLException{ String sql = "select * from contentinfo1 where title =? "; Cursor cursor = db.rawQuery(sql, new String[] {word}); return cursor; }
实现精确匹配后,依葫芦画瓢的想制作模糊搜索,套用了SQL语句,不料出错
public Cursor getTitle(String word) throws SQLException{ String sql = "select * from contentinfo1 where title like '%"+word+"%'"; Cursor cursor = db.rawQuery(sql, new String[] {word}); return cursor; }
解决方法:
public Cursor getTitle(String word) throws SQLException{ String sql = "select * from contentinfo1 where title like '%"+word+"%'"; Cursor cursor = db.rawQuery(sql,null); return cursor; }
原因:更改语句之后用了+word+而非占位符 ?, 所以rawQuery第二个参数不知道和哪个对应故出现报错
进一步修改方案可以参照
http://stackoverflow.com/questions/5716543/android-sqliteexception-bind-or-column-index-out-of-range-problem
需要将第二个rawquery参数更改为NULL
关注微信公众号,最新技术实时推送
转载请注明:尼古拉斯.赵四 » Android 模糊搜索rawquery bind or column index out of range: handle 0x2fb180 报错