加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在SQLite数据库中获取新插入数据自增长的ID值(传智播客笔记)

发布时间:2020-12-12 20:31:02 所属栏目:百科 来源:网络整理
导读:在SQLite数据库中获取新插入数据自增长的ID值 使用last_insert_rowid()函数,例如: SQLiteDatabase db = helper.getWritableDatabase(); db.execSQL("insert into person(name,phone,amount) values(?,?,?) ",new Object[]{person.getName(),person.getPhon

在SQLite数据库中获取新插入数据自增长的ID值

使用last_insert_rowid()函数,例如:

        SQLiteDatabase  db = helper.getWritableDatabase();
        db.execSQL("insert into person(name,phone,amount) values(?,?,?) ",new Object[]{person.getName(),person.getPhone(),person.getAmount()});
        Cursor cursor = db.rawQuery("select last_insert_rowid() from person",null);        
        int strid;  
        if(cursor.moveToFirst())
           strid = cursor.getInt(0);
        Log.i("testAuto",strid+"");

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读