SQLite数据库操作,请问下这里面的movetoFirst到底有何用意?

宵 宵 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
代码如下:
public Person find(Integer id)
{
SQLiteDatabase db = helper.getReadableDatabase();
Cursor cursor = db.rawQuery("select * from person where personsId = ?",
new String[]{id.toString()});

if(cursor.moveToFirst())
{
int personsId = cursor.getInt(cursor.getColumnIndex("personsId"));
String name = cursor.getString(cursor.getColumnIndex("name"));
String phone =cursor.getString(cursor.getColumnIndex("phone"));

return new Person(personsId,name,phone);
}

return null;
}


既然都找到了,为什么还需要movetoFirst。
因为这个cursor返回的可能不只是一行么。为什么?
...全文
评论 2
收藏 已收藏
分享
返回顶部
宵
Android 80,490 成员 91,371 内容