我正在尝试从我的 sqlite database
public Integer deleteData (String id){
SQLiteDatabase db = this.getWritableDatabase();
return db.delete(TABLE_NAME, "id" + "=?", new String[]{id});
}
到目前为止,delete
查询运行良好。但是我很难找到id
特定行的细节。
我试图根据特定的字段内容查询数据。
public Integer getId(String desc, Integer id){
SQLiteDatabase db = this.getWritableDatabase();
db.rawQuery("SELECT id FROM fap_table WHERE description = '"+desc+"'" , null);
return id;
}
但我不断收到错误。我如何查询数据库行以检索其 ID。请帮忙。
使用此代码获取 ID:
public int getRow(String desc){
int id = 0;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery("SELECT id FROM fap_table WHERE description = '"+desc+"'" , null);
if (cursor != null) {
if (cursor.moveToFirst())
id = cursor.getInt(0);
cursor.close();
}
db.close();
return id;
}
您的代码出现错误,无法将结果分配给db.rawQuery()
游标对象。
db.rawQuery()
返回您需要的游标,并从中提取唯一的列(如果存在),即id。
如果游标为空,则返回0
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句