Get last inserted value from sqlite database Android

前端 未结 9 591
不思量自难忘°
不思量自难忘° 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 07:56

    If you want the last_insert_id just afert a insert you can use that :

    public long insert(String table, String[] fields, String[] vals ) 
    {
        String nullColumnHack = null;
        ContentValues values = new ContentValues();
        for (int i = 0; i < fields.length; i++) 
        {
            values.put(fields[i], vals[i]); 
        }
    
        return myDataBase.insert(table, nullColumnHack, values);
    }
    

提交回复
热议问题