SQLite In Android Studio Simple Example Step By Step

Hello, developers. Welcome to SQLite In Android Studio Example.

This SQLite In Android tutorial will cover the simple operation of SQLite databases like insert and display data.

SQLite In Android tutorial is mainly targeted towards beginners with source code to download.

If you want to do all crud operations (insert, update, delete, display) with multiple table, then visit SQLite with multiple tables android

If you want to do all crud operations with one table, then visit Android Crud Operations In SQLite .

First, check the output of SQLite In Android Studio example, then we will develop it.

Download Source Code


Creating SQLite In Android Studio Tutorial step by step

Step 1: Create a new project in Android Studio.

Step 2: Creating DatabaseHelper class

Create a new class named “DatabaseHelper” and all below source code

Step 3: Description of DatabaseHelper

Database name, Database version, table name and column names of tables are written as below.

Understanding most important part of SQLite Database

In onCreate() method, create statement for the table is written.

In onUpgrade() method, already exist tables are dropped and then all tables are recreated.

onCreate() method is called within onUpgrade() method to create tables.

In following scenarios, you need to upgrade DATABASE_VERSION number in increment order.

  1. When you add, update or delete any column of any table in the whole database.
  2. When you update any column name of any table.
  3. When you add, update or delete any table.
  4. When you update table name.

When DATABASE_VERSION is updated in increment order, onUpgrade() method is called.

addStudentDetail() method will add name to database.

getAllStudentsList() method will fetch all values of names from database.

Step 5: Updating activity_main.xml

Put following code in activity_main.xml

Step 6: Updating MainActivity.java

Add following  in MainActivity.java

When the user clicks on store button, the entered text is stored in the database as below.

When a user clicks on the getall button, all the names are fetched from the database.

For all crud operations (insert, update, delete, display) visit this: Crud Operations In SQLite Android  

So that is all for SQLite in Android example.

Feel free to comment your queries and reviews in the comment section. Thank you 🙂

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

4 Responses

  1. Moazzem says:

    Where is the student_database.bd file?

  2. cuiqx says:

    great job!

    And i have one question .

    I would like for the done(Enter) button on the keyboard to trigger the STORE button.

    can you show me how to do this ?

    many thanks

Leave a Reply

Your email address will not be published. Required fields are marked *