0

为什么我收到此代码错误?

public Cursor getAllTitlesFromInnerListGroup(String tablename, String grp) {
    String[] columns = new String[]{KEY_ROWID_T, KEY_NAME_T, KEY_PRIORITY_T, KEY_FINISHED_T, KEY_NOTES_T, KEY_HIDDEN_T, KEY_QUANTITY_T, KEY_GROUP_T};
    //return ourDatabase.query("GL_" + tablename, columns, KEY_GROUP_T + "='Volvo'", null, null, null, null); //this works
    return ourDatabase.query("GL_" + tablename, columns, KEY_GROUP_T + "=" + grp, null, null, null, null);
}

04-18 21:10:53.118: E/AndroidRuntime(30721): 引起: android.database.sqlite.SQLiteException: 没有这样的列: Volvo: 编译时: SELECT _id, grlist_name, grlist_priority, grlist_finished, grlist_notes, grlist_hidden, grlist_quantity, grlist_group FROM GL_table WHERE grlist_group=Volvo

4

1 回答 1

2

改变这个:

return ourDatabase.query("GL_" + tablename, columns, KEY_GROUP_T + "=" + grp,
null, null, null, null);

对此:

return ourDatabase.query("GL_" + tablename, columns, KEY_GROUP_T + "= ?" ,
new String[]{grp}, null, null, null);
于 2012-04-18T21:26:29.170 回答