Thursday, January 5, 2012

Android SQLite Primary Key Auto Increment

WRONG :
CREATE TABLE PERSON (ID INTEGER PRIMARY KEY AUTOINCREMENT,
FIRSTNAME TEXT,
LASTNAME TEXT)

WRONG :
CREATE TABLE PERSON (ID INT PRIMARY KEY AUTOINCREMENT,
FIRSTNAME TEXT,
LASTNAME TEXT)

CORRECT :
CREATE TABLE PERSON (ID INTEGER PRIMARY KEY,
FIRSTNAME TEXT,
LASTNAME TEXT)

Java Code To Insert (Do Not Set ID field):
ContentValues values = new ContentValues();
values.put("FIRSTNAME", "Java");
values.put("LASTNAME", "Padawan");


Then on your SQLiteDatabase instance do :
sqlDatabase.insert("PERSON" null, values);

2 comments:

Anonymous said...

thanks :)

Anonymous said...

thanks :)

Email

java.padawan@androidph.com