Marcos Vasconcelos Marcos Vasconcelos - 1 year ago 157
Android Question

Get generated id after insert

I'm using the SQLite with Android, and I want to know the best way to get the generated id of the row I inserted.

A solution I think is make a search after include, but it's doesn't look the best way.

Answer Source

The insert method returns the id of row just inserted or -1 if there was an error during insertion.

long id = db.insert(...);

where db is SQLiteDatabase.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download