Android SQLiteOpenHelper Class

The android.database.sqlite.SQLiteOpenHelper class is used for database creation and version management.

To perform any database operation, you have to provide the implementation of onCreate() and onUpgrade() methods of SQLiteOpenHelper class.

Constructors of SQLiteOpenHelper class

ConstructorDescription
SQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version)It creates an object for creating, opening and managing the database.
SQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version, DatabaseErrorHandler errorHandler)It also creates an object for creating, opening and managing the database. It specifies the error handler.
Constructors of SQLiteOpenHelper class

Methods of SQLiteOpenHelper class

MethodDescription
public abstract void onCreate(SQLiteDatabase db)It is called only once when database is created for the first time.
public abstract void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)This method is called when database needs to be upgraded.
public synchronized void close ()It closes the database object.
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion)It is called when database needs to be downgraded.
Methods of SQLiteOpenHelper class