2

Given the following code:

 sqLiteDatabase.execSQL("create table if not exists ACCOUNT (ID integer primary key autoincrement," +
                        "CASH LONG NOT NULL," +
                        "BANKID INTEGER NOT NULL," +
                        "ACCOUNTNO TEXT ," +
                        "DATE TEXT NOT NULL," +
                        "COMMENT TEXT);");

A table is created in SQLite.

How can I get a lastID after adding a record?

With the following code:

 contentValues.put("CASH", accountTO.getCash());
 contentValues.put("DATA", DatePro.currentDate());
 contentValues.put("BANKID", accountTO.getBankID());
 contentValues.put("ACCOUNTNO", accountTO.getAccountNo());
 contentValues.put("COMMENT", accountTO.getComment());

 Long i = sqLiteDatabase.insert("ACCOUNT", null, contentValues);

I get -1.

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
user2049371
  • 189
  • 1
  • 2
  • 16

1 Answers1

6
public long insert (String table, String nullColumnHack, ContentValues values)

Returns the rowID of the newly inserted row, or -1 if an error occurred.

A. Alencar
  • 141
  • 2
  • 8
JaveZh
  • 184
  • 3