0% found this document useful (0 votes)
8 views1 page

SQLite Unit 2 Answer BCU

SQLiteOpenHelper is an abstract class in Android Studio that aids in managing database creation and versioning. Key methods include onCreate for initial database creation, onUpgrade for handling version changes, and methods to obtain writable or readable database instances. An example implementation demonstrates creating a 'users' table and handling upgrades by dropping the existing table and recreating it.

Uploaded by

VARUN MUDALIAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

SQLite Unit 2 Answer BCU

SQLiteOpenHelper is an abstract class in Android Studio that aids in managing database creation and versioning. Key methods include onCreate for initial database creation, onUpgrade for handling version changes, and methods to obtain writable or readable database instances. An example implementation demonstrates creating a 'users' table and handling upgrades by dropping the existing table and recreating it.

Uploaded by

VARUN MUDALIAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

SQLite Unit 2 Answer BCU

MOBILE APPLICATION DEVELOPMENT UNIT 2 (BCU Skyward Publisher)

SQLite Topic

Q12: Methods of SQLiteOpenHelper Class in Android Studio

SQLiteOpenHelper is an abstract class that helps manage database creation and version management.

Key Methods:

- onCreate(SQLiteDatabase db): Called when the database is created for the first time.

- onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion): Called when database version changes.

- getWritableDatabase(): Returns a writable database instance.

- getReadableDatabase(): Returns a readable database instance if writable not available.

- close(): Closes the database.

Example:

public class MyDBHelper extends SQLiteOpenHelper {

public MyDBHelper(Context context) {

super(context, "mydb", null, 1);

public void onCreate(SQLiteDatabase db) {

db.execSQL("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)");

public void onUpgrade(SQLiteDatabase db, int oldV, int newV) {

db.execSQL("DROP TABLE IF EXISTS users");

onCreate(db);

You might also like