假坚强 发表于 2013-8-28 16:30

Android程序查询包含“*" "#”的号码时出错的解决办法

5 本帖最后由 vincy西西1010 于 2012-7-4 17:39 编辑       代码错误提示:   
E/AndroidRuntime(1145): Caused by: android.database.sqlite.SQLiteException: near "*": syntax error: , while compiling: SELECT numbertype, new, duration, _id, numberlabel, name, number, type, date FROM calls WHERE (number = **9) ORDER BY date desc   
   
解决:   
1.    strQuery = "number = " + strQueryNumber;   
2.            callLogCursor = TApplication.nowTApplication.getContentResolver()   
3.                  .query(CallLog.Calls.CONTENT_URI, null, strQuery, null,   
4.                            "date desc");                           
查询代码改成:   
1.                              
2.                              strQuery = "number = " + "strQueryNumber";   
3.            callLogCursor = TApplication.nowTApplication.getContentResolver()   
4.                  .query(CallLog.Calls.CONTENT_URI, null, strQuery, null,   
5.                            "date desc");   
总结:因为"*"为数据库里的关键字(未经证实),所有查找是会报语法错误,只需要拼接字符串,把"*"改成非关键字即可ps:模拟器不知道为何直接拔打数字+"#"会清空屏幕,而只能拨打"#"开头的号码   
   
   
   
页: [1]
查看完整版本: Android程序查询包含“*" "#”的号码时出错的解决办法