I am trying to create a method to extract the maximum id from my table, but I have problems.
This is my method. It works, but the return value is 0,
public int getLastId() { openDB(); int id = 0; final String MY_QUERY = "SELECT MAX(_id) AS _id FROM organize"; Cursor mCursor = mDb.rawQuery(MY_QUERY, null); try { if (mCursor.getCount() > 0) { mCursor.moveToFirst(); id = mCursor.getInt(mCursor.getColumnIndex(MY_QUERY)); } } catch (Exception e) { System.out.println(e.getMessage()); } finally { closeDB(); } return id; }
I can fix this problem, thanks a lot
user836807
source share