我有一个表,我想在计数大于 1 时更新现有值。
这是我的代码:
public int getCount(String clues) {
Cursor c = null;
try {
db = this.getReadableDatabase();
String query = "select count(*) from " + TABLE_NAME + "where CLUES_VALUES = ?";
c = db.rawQuery(query, new String[] {clues});
if (c.moveToFirst()) {
return c.getInt(0);
}
return 0;
}
finally {
if (c != null) {
c.close();
}
if (db != null) {
db.close();
}
}
}
我正在根据“CLUES_VALUES”列进行检查。我从数据库中获取值并检查它是否在 "CLUES_VALUES"列中包含多个相似值。如果它包含那么它将更新整行否则它不会。 当我执行代码时,出现以下错误
android.database.sqlite.SQLiteException: near "=": syntax error (code 1): , while compiling: select count(*) from puzzl_tablewhere CLUES_VALUES = ?
Clues_values 列包含“字符串值” 我不知道我在哪里失踪。请帮忙。
最佳答案
你在“where”前面少了一个空格。
String query = "select count(*) from " + TABLE_NAME + " where CLUES_VALUES = ?";
关于android - 当 SqLite 中特定值的计数大于 1 时更新表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37019333/