我正在我正在制作的应用程序中实现搜索,我正在我的dbhelper类搜索方法中编写这一行,当我在editText中按Enter或退格键时,应用程序崩溃了,我已经连接到onkeylistener ...
Cursor c = sqldb.query(courseTable, columnNames, course + " LIKE %?%", selectionVals, null, null, null);
我在logcat
中收到此错误/异常H/AndroidRuntime(21777): android.database.sqlite.SQLiteException: near "%": syntax error: , while compiling: SELECT course_name, assessment_type, obtained_marks, total_marks FROM Course WHERE course_name LIKE %?%
我被困在这里。如何解决这个问题。
感谢。
答案 0 :(得分:1)
我相信你的通配符周围需要单引号。
所以
sqldb.query(courseTable, columnNames, course + " LIKE %?%", selectionVals, null, null, null);
成为
sqldb.query(courseTable, columnNames, course + " LIKE '%?%'", selectionVals, null, null, null);
我不确定是否要逃避它们,如果java编译器抱怨它,你可能需要这样做。
希望有所帮助!