Android sqlite查询带字符串的位置

时间:2012-04-18 21:20:27

标签: android sqlite

为什么我的代码出错?

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:没有这样的列:沃尔沃:,   编译时:SELECT _id,grlist_name,grlist_priority,   grlist_finished,grlist_notes,grlist_hidden,grlist_quantity,   grlist_group FROM GL_table WHERE grlist_group = Volvo

1 个答案:

答案 0 :(得分: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);