日期:2014-05-16  浏览次数:20429 次

android- 数据库 模糊搜索, 单引号 ’ 报错问题(SQLiteException: unrecognized token: “‘)
android- 数据库 模糊搜索, 单引号 ’ 报错问题(SQLiteException: unrecognized token: “‘)

cursor = MainActivity.this.getContentResolver().query(uri, new String[]{"display1"}, "display1"+" like" +" '%"+tempSearchContent+"%'", null, "date desc");这样进行模糊搜索,如果tempSearchContent 为 ‘(单引号),需要对 其进行转义
或者 使用selectionArgs 参数:

String like = "%" + tempSearchContent + "%";

cursor = MainActivity.this.getContentResolver().query(uri, new String[]{"display1"}, "display1 like?", new String[]{like}, "date desc");

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zhjp4295216/archive/2010/11/23/6028849.aspx