我正在尝试搜索标题以“n”开头的笔记,但我不知道我的查询出了什么问题,我遇到了强制关闭错误。
这是我的日志:
04-01 12:19:37.833: D/AndroidRuntime(676): Shutting down VM
04-01 12:19:37.833: W/dalvikvm(676): threadid=1: thread exiting with uncaught exception (group=0x40015560)
04-01 12:19:37.913: E/AndroidRuntime(676): FATAL EXCEPTION: main
04-01 12:19:37.913: E/AndroidRuntime(676): android.database.sqlite.SQLiteException: near "%": syntax error: , while compiling: SELECT DISTINCT _id, title, body, cdate, passw FROM notes WHERE title LIKE n%
04-01 12:19:37.913: E/AndroidRuntime(676): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
04-01 12:19:37.913: E/AndroidRuntime(676): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)
这是代码:
public Cursor search(String title) {
Cursor mCursor =
mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
KEY_TITLE, KEY_BODY,KEY_CDATE,KEY_PASS}, KEY_TITLE + " LIKE" +" " + title + '%', null,
null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}