怎样查询sqlite数据库中的最后一条数据

2024-11-06 19:04:59
推荐回答(1个)
回答(1):

public Cursor GetTable_sex_Info_by_given_id(int _id)
{
Cursor c = null;
try{
String col[] = { "sex" };
c= db.query("TableName",col, "_id='"+_id+"'", null, null, null, null);
// (TableName,是你的表名)
}catch(Exception e){
Log.e("get sex info failed:","e="+e.getMessage());
}
return c ;
}
得到这个cursor,再获取你要的数据:
Cursor sex_cursor=(Cursor)GetTable_sex_Info_by_given_id(_id);
//(这个_id,是你得到的个人的_id)
sex_cursor.moveToFirst();
while(!sex_cursor.isAfterLast())
{
String sex_str = (String)sex_cursor.getString(0);
Toast.makeText(this, "此人性别:"+sex_str,Toast.LENGTH_SHORT).show();
sex_cursor.moveToNext();
}
sex_cursor.close();