VOOZH about

URL: https://www.geeksforgeeks.org/android/how-to-pre-populate-database-in-android-using-sqlite-database/

⇱ How to pre populate database in Android using SQLite Database - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to pre populate database in Android using SQLite Database

Last Updated : 27 Sep, 2025

Introduction :

Often, there is a need to initiate an Android app with an already existing database. This is called prepopulating a database. In this article, we will see how to pre-populate database in Android using SQLite Database. The database used in this example can be downloaded as Demo Database.

To prepopulate a SQLite database in an Android application, you can follow these steps:

  1. Create a new SQLite database in your Android application.
  2. Create a SQL script that contains the data you want to prepopulate your database with. This script should contain the SQL commands to create tables, insert data, and perform other database operations.
  3. Store the SQL script in the assets folder of your Android application.
  4. In the onCreate() method of your SQLiteOpenHelper subclass, open the database and execute the SQL script to populate the database with data.

Here is an example code snippet that demonstrates how to prepopulate a SQLite database in an Android application : 

Approach:

Add the support Library in build.gradle file and add Recycler View dependency in the dependencies section. 

  • Make sure you add the database in assets folder. To create assets folder right click on app directory->new->Folder->(select)Assets Folder. Then simply paste your .db file in assets folder.
  • In activity_main.xml, add the following code. 
  • Create a new custom_layout.xml file with the following code. 
  • Create a DatabaseHelper class and add the following code. 
  • Create a MyAdapter.java class and add the following code. 
  • Finally, in MainActivity.java add the following code. 

Output:👁 Image

Comment
Article Tags:
Article Tags:

Explore