Programming Tips - Java: Find the id of the row I just inserted (in sqlite)

Date: 2012apr2 Language: SQLite, Java Q. Java: Find the id of the row I just inserted (in sqlite) A. Use:
SELECT last_insert_rowid()
Here's some Java code that does that (but it can be done in any language):
public int getLastInsertRowId() { int result_id = -1; final String sql = "SELECT last_insert_rowid()"; Cursor c = null; try { c = getReadableDatabase().rawQuery(sql, null); if (c.getCount() > 0) { c.moveToFirst(); result_id = c.getInt(0); } } finally { if (c != null) { try { c.close(); } catch (SQLException e) { } } } return result_id; }