I am new to Android and I have to create an application where I need to use a SQLite database.
I am not so well equipped with the SQLite.
Could you tell me what the purpose and use of the SQLiteOpenHelper class, and provide a simple database creation and insertion example?
Sqlite helper class helps us to manage database creation and version management.
SQLiteOpenHelper takes care of all database management activities. To use it,
1.Override
onCreate(), onUpgrade()methods ofSQLiteOpenHelper. Optionally override onOpen() method.2.Use this subclass to create either a readable or writable database and use the SQLiteDatabase’s four API methods
insert(), execSQL(), update(), delete()to create, read, update and delete rows of your table.Example to create a MyEmployees table and to select and insert records:
Now you can use this class as below,
Now you can use MyDB class in you activity to have all the database operations. The create records will help you to insert the values similarly you can have your own functions for update and delete.