2012-07-02 48 views
0

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 }); 

回答

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. 
+0

大声笑..我读这给定链路至少两次,但似乎我并没有注意。谢谢。 –

0

SELECT关键字之后你有?,而不是像*

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 
      }); 
+0

这是字符串。对不起,不太清楚。 –