PREF_NAME,PREF_STATUS - 文字
它给了我这个错误:
07-02 14:08:07.457: E/AndroidRuntime(17295): android.database.sqlite.SQLiteException: near "?": syntax error: , while compiling: SELECT ? FROM ? WHERE ? = ?
我正在使用的代码是:
Cursor c = db.rawQuery("SELECT ? FROM ? WHERE ? = ?", new String[]{ PREF_STATUS,
PREF_TABLE, PREF_NAME, assigned_pref_name });
答案 0 :(得分:3)
根据documentation,你只能把“?”在where子句:
public Cursor rawQuery (String sql, String[] selectionArgs)
Parameters
sql the SQL query. The SQL string must not be ; terminated
selectionArgs You may include ?s in where clause in the query, which will be replaced by the values from selectionArgs. The values will be bound as Strings.
答案 1 :(得分:0)
在SELECT
关键字之后,您有?
而不是*
。
答案 2 :(得分:0)
我想你想把assigned_pref_name作为一个字符串传递而不是变量名,所以:
Cursor c = db.rawQuery(
"SELECT ? FROM ? WHERE ? = ?",
new String[]{
PREF_STATUS,
PREF_TABLE,
PREF_NAME,
"assigned_pref_name" //as a string
});