我想检查值是否存在于列中。例如,我想检查列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 COUNT(11303): [email protected]
。
我也尝试过使用:
getStar = db.rawQuery("SELECT count(*) FROM "
+ TABLE_NAME + " WHERE artId = '" + entryId + "'", null);
,但我得到了同样的结果。
所以我希望对你有所帮助。
Upvote for'if(getStar.getCount()> 0)'。 – Sam
非常感谢您的帮助。有用。 – Sabre
第一种解决方案也适用。至少当没有值存在和何时只存在1个值时。 – Sabre