我的查询是
return database.rawQuery(“SELECT * FROM”+ TABLE_NAME +“WHERE”+ HISTORY_COLUMN_NAME +“=”+ pref.getString(“KEY”,null),null);
错误是
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sset.jibin.wakemethere/com.sset.jibin.wakemethere.History}: android.database.sqlite.SQLiteException: near "=": syntax error (code 1): , while compiling: SELECT * FROM history WHERE name =
使用query()修复它。
答案 0 :(得分:1)
您需要转义参数,如下所示:
return database.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE " + HISTORY_COLUMN_NAME + " = '" + pref.getString("KEY", null) + "'", null);
这将导致SELECT * FROM <table> WHERE <column> = '<value>'
使用query()
代替rawQuery()
让SDK逃脱您的参数会更明智。您的查询中没有任何内容对query()
来说太难了。