gpt4 book ai didi

android - 如何检查列中是否存在特定值?

转载 作者:行者123 更新时间:2023-11-29 14:53:03 26 4
gpt4 key购买 nike

我正在尝试检查该值是否存在于列中。例如,我想检查 artId 列是否包含一些数值。我正在使用以下代码:

getStar = db.query(TABLE_NAME, new String[] { "artId" },
"artId = " + entryId, null, null,
null, null);
getStar.moveToFirst();
String star = getStar.toString();
Log.w("ID COUNT", star);
if(getStar != null) {
// do something
}

其中 entryId 是一些数字。

但我总是得到这样的结果:

W/ID 计数(11303):android.database.sqlite.SQLiteCursor@41aa4c80

我也尝试使用:

getStar = db.rawQuery("SELECT count(*) FROM "
+ TABLE_NAME + " WHERE artId = '" + entryId + "'", null);

但我得到了相同的结果。

所以我希望得到你的帮助。

最佳答案

Cursor 是有效的(非null),是的,因为它没有错误。相反,检查它是否有任何数据。

getStar = db.rawQuery("SELECT count(*) FROM " + TABLE_NAME + " WHERE artId = '" + entryId + "'", null);
getStar.moveToFirst();
if (getStar.getInt(0)) { // This will get the integer value of the COUNT(*)
// It has data
}

我对上面的结果有点不确定;相反,您可以查询结果数:

getStar = db.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE artId = '" + entryId + "'", null);
if (getStar.getCount() > 0) { // This will get the number of rows
// It has data
}

关于android - 如何检查列中是否存在特定值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12679584/

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