SQLite_Database_Operations
SQLite_Database_Operations
To create a database, you subclass SQLiteOpenHelper and override the onCreate() method:
@Override
db.execSQL("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)");
@Override
onCreate(db);
This creates a table named 'users' when the database is first created.
a. getWritableDatabase()
SQLiteDatabase db = dbHelper.getWritableDatabase();
Creating, Opening, and Closing SQLite Database in Android
b. getReadableDatabase()
SQLiteDatabase db = dbHelper.getReadableDatabase();
Even though Android handles this, it's best practice to close the database manually:
Quick Recap
| Operation | Method |
|---------------|--------------------------------------------|