Multiple choice

Which of the following is the correct syntax of onUpgrade method in SQLite database?

  1. public void onUpgrade(SQLiteDatabase db) { db.execSQL(DROP TABLE IF EXISTS + TABLE_CONTACTS); onCreate(db); }

  2. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL(DROP TABLE IF EXISTS + TABLE_CONTACTS); onCreate(db); }

  3. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL(DROP TABLE IF EXISTS + TABLE_CONTACTS); onCreate(db); db.insert(); }

  4. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL(DROP TABLE IF EXISTS + TABLE_CONTACTS); onCreate(db); db.close(); }

  5. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL(DROP TABLE IF EXISTS + TABLE_CONTACTS); onCreate(db); db.delete(); }

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

onUpgrade() method is called when there is a database version mismatch.