I am getting this error
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jitendra.ori/com.example.jitendra.ori.CatalogActivity}: android.database.sqlite.SQLiteException: near "add": syntax error (code 1): , while compiling: CREATE TABLE add (_id INTEGER PRIMARY KEY AUTOINCREMENT, add1 TEXT NOT NULL, add2 TEXT NOT NULL, add3 TEXT NOT NULL, city TEXT, pin INTEGER NOT NULL DEFAULT 0);
My Database create command:
public void onCreate(SQLiteDatabase db) {
String SQL_CREATE_PETS_TABLE = "CREATE TABLE " + AddEntry.TABLE_NAME + " ("
+ AddEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ AddEntry.COLUMN_ADD1 + " TEXT NOT NULL, "
+ AddEntry.COLUMN_ADD2 + " TEXT NOT NULL, "
+ AddEntry.COLUMN_ADD3 + " TEXT NOT NULL, "
+ AddEntry.COLUMN_CITY + " TEXT, "
+ AddEntry.COLUMN_PIN + " INTEGER NOT NULL DEFAULT 0);";
db.execSQL(SQL_CREATE_PETS_TABLE);
}
Database contract :
public final static String TABLE_NAME = "add";
public final static String _ID = BaseColumns._ID;
public final static String COLUMN_ADD1 ="add1";
public final static String COLUMN_ADD2 = "add2";
public final static String COLUMN_ADD3 = "add3";
public final static String COLUMN_CITY = "city";
public final static String COLUMN_PIN= "pin";
Please tell what is wrong in this create table command
add
is a sqlite keyword and cannot be used as identifier such as table name without quoting. Better rename the table.