Android SQLite从列中获取值

时间:2016-03-22 06:11:23

标签: android sqlite

我有一个ShopName列,另一个名为LocationCode的列,如果LocationCode等于" SKP",相应的send将被添加到一个数组中,我的问题是,我该怎么办?那样做?

我有这样的事情:

ShopName

还有另外一个类:

public List<String> getQuotes() {
    String WhiteFarm = "WhiteFarm";
    List<String> list = new ArrayList<>();
    Cursor cursor = database.rawQuery("SELECT * FROM WhereToEat WHERE 'LocationCode' = " + WhiteFarm, null);
    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        list.add(cursor.getString(0));
        cursor.moveToNext();
    }
    cursor.close();
    return list;
}

1 个答案:

答案 0 :(得分:1)

如果您的LocationCode包含String(或SQLite的TEXT)数据类型,那么您的值应该包含在单引号中,如下面的代码所示:

Cursor cursor = database.rawQuery("SELECT * FROM WhereToEat WHERE LocationCode = " + "'" + WhiteFarm "'", null);