mardi 10 février 2015

How to use sqlite to retrieve single result?

I have this code that retrieves the last id



public int retrieveLastId() {

SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery("select "+ RECORDING_ID +" from " + DATABASE_TABLE + " ORDER BY "+ RECORDING_ID +" DESC LIMIT 1 ", null);


int last = 0;
last = Integer.parseInt(cursor.getString(0));
Log.e("sfsdlkfjs dfl sd",cursor.getString(0));
return last;
}


but I get an error android.database.cursorindexoutofboundsexception how do I return the last id properly?


Aucun commentaire:

Enregistrer un commentaire