gpt4 book ai didi

android - 从 sqlite 中获取数据,WHERE 子句中的错误

转载 作者:行者123 更新时间:2023-11-30 03:43:27 25 4
gpt4 key购买 nike

我不知道哪里出错了,我是 android 开发的新手,正在尝试使用 SQLITE 数据库编写一些代码:

我有一个名为 cards 的数据库和一个名为 mycards 的表我的创建语句是:

private static final String DATABASE_CREATE =
"create table mycards(card_id integer primary key autoincrement, "
+ NAME + " text not null, card_type text not null,json_string text not null);";

我的插入函数如下:

 public long insertCard(String name, String type, String json_string) {
ContentValues initialValues = new ContentValues();
initialValues.put(NAME, name);
initialValues.put(TYPE, type);
initialValues.put(JSON, json_string);
return mDb.insert(DATABASE_TABLE, null, initialValues);
}


//here TYPE is card_type

在 card_type 列中有三个可能的值 Pcard、Bcard、Ccard。当我想检索数据时,我希望它根据 card_type 列中的值(字符串)进行过滤。

因此我的获取函数是:(仅显示一种类型):

 public Cursor fetchallPCards() {



return mDb.query(DATABASE_TABLE, new String[] {"card_name"},TYPE+"="+"Pcard", null, null, null, null);

}

但我收到错误:

03-14 00:26:21.233: E/SQLiteLog(701): (1) no such column: Pcard

我哪里做错了?据我所知,我认为我是对的。

最佳答案

您需要在查询中的字符串周围加上引号,尝试:

return mDb.query(DATABASE_TABLE, new String[] { "card_name" }, TYPE + "=" + "'Pcard'", null, null, null, null);

关于android - 从 sqlite 中获取数据,WHERE 子句中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15394276/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com