VOOZH about

URL: https://www.geeksforgeeks.org/android/how-to-read-data-from-sqlite-database-in-android/

⇱ How to Read Data from SQLite Database in Android? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Read Data from SQLite Database in Android?

Last Updated : 23 Jul, 2025

In the 1st part of our SQLite database, we have seen How to Create and Add Data to SQLite Database in Android. In that article, we have added data to our SQLite Database. In this article, we will read all this data from the SQLite database and display this data in RecyclerView

What we are going to build in this article? 

We will be working on the existing application which we have built in our previous article. In that application, we are simply adding the course list part where we can get to see our list of courses. A sample video is given below to get an idea about what we are going to do in this article.  

Step-by-Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.

Note that select Java as the programming language.

Below is the complete project file structure after performing the read operation:

👁 Read


Step 2: Working with the activity_main.xml file

Go to the activity_main.xml file and add a new Button to open a new activity for displaying our list of courses. 


Now below is the updated code for the activity_main.xml file after adding the above code snippet.


Step 3: Creating a modal class for storing our data

Navigate to the app > java > your app's package name > Right-click on it > New > Java class and name it as CourseModal and add the below code to it. Comments are added inside the code to understand the code in more detail.


Step 4: Updating our Java class for performing SQLite operations.  

Navigate to the app > java > your app's package name > DBHandler and add the below code to it. In this, we are simply adding a new method for reading all the courses from the SQLite database.


Below is the updated code for the DBHandler.java file after adding the above code snippet.


Step 5: Creating a new Activity for displaying our list of courses

To create a new Activity we have to navigate to the app > java > your app’s package name > Right click on package name > New > Empty Activity and name your activity as ViewCourses and create new Activity. Make sure to select the empty activity.  


Step 6: Working with the MainActivity.java file 

As we have added a new button to our activity_main.xml file so we have to add setOnClickListener() to that button in our MainActivity.java file. 


Below is the updated code for the MainActivity.java file after adding the above code snippet.


Step 7: Creating a new layout file for our item of RecyclerView 

Navigate to the app > res > layout > Right-click on it > New > Layout resource file and name it as course_rv_item and add the below code to it. 


Step 8: Creating an Adapter class for setting data to our items of RecyclerView

Navigate to the app > java > your app's package name > Right-click on it > New > Java class and name it as CourseRVAdapter and add the below code to it. Comments are added inside the code to understand the code in more detail.


Step 9: Working with the activity_view_courses.xml file

Navigate to the app > res > layout > activity_view_courses.xml and add the below code to that file. Below is the code for the activity_view_courses.xml file. 


Step 10: Working with the ViewCourses.java file

Navigate to the app > java > your app's package name > ViewCourses.java file and add the below code to it. Comments are added inside the code to understand the code in more detail.

Now run your app and see the output of the app. Make sure to add the data before reading the data. 

Output:


Comment

Explore