

It returns an instance of SQLite database which you have to receive in your own object.

SQLiteDatabase db = this.getReadableDatabase() Ĭursor res = db.rawQuery( "select * from contacts", null ) ĪrrayList.add(res.getString(res.getColumnIndex(CONTACTS_COLUMN_ID))) In order to create a database you just need to call this method openOrCreateDatabase with your database name and mode as a parameter. SQLiteDatabase db = this.getWritableDatabase() Public Integer deleteContact (Integer id) Public class DBHelper extends SQLiteOpenHelper )

– It allow to delete specific contact record in the database.
#Android sqlite database tutorial update#
– It allow to update the contact name, phone and email to the contact table in the database. – Get the specific contact information from the contact table.īoolean updateContact (Integer id, String name, String phone, String email) – It allow to insert the contact name, phone and email to the contact table in the database. – This method will activate when the Database version has been changed.īoolean insertContact (String name, String phone, String email) Void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) – This method will call when the database is create for the first time. The Following are the source code of DBHelper.java class, this class should extends SQLiteOpenHelper to enable the create, retrieve, update and delete features. You can type any java class name for example My class name is DBHelper.Įxtends SQLiteOpenHelper and edit the class Right click your package name > New > Java Class. I name my table name as DBExample and below are the structure and content of the table. Try to prepare a database table you will need to create a SQLite database later. Choose “Empty Project” and Click Next buttonĥ. Select Minimum SDK (API 15:Android 4.0.3 (IceCreamSandwich) and Click Next button.Ĥ. After that click next button to proceed.ģ. (Optional) You can edit the company domain or select the suitable location for current project tutorial. Create a new project and Edit the Application name to “SQLiteExample”. Open Android Studio IDE in your computer.Ģ.
