Get last inserted value from sqlite database Android

前端 未结 9 632
不思量自难忘°
不思量自难忘° 2020-11-29 07:11

I am trying to get the last inserted rowid from a sqlite database in Android. I have read a lot of posts about it, but can\'t get one to work. This is my method:



        
9条回答
  •  盖世英雄少女心
    2020-11-29 08:10

    I use this

    public int lastId(){
        SQLiteDatabase db =  
      this.getReadableDatabase();
        Cursor res =  db.rawQuery( "select * from resep", null );
        res.moveToLast();
        return res.getInt(0);
    }
    

提交回复
热议问题