VOOZH about

URL: https://www.geeksforgeeks.org/kotlin/how-to-update-data-to-sqlite-database-in-android-using-jetpack-compose/

⇱ How to Update Data to SQLite Database in Android using Jetpack Compose? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Update Data to SQLite Database in Android using Jetpack Compose?

Last Updated : 23 Jul, 2025

We have seen How to Create and Add Data to SQLite Database in Android using Jetpack Compose as well as How to Read Data from SQLite Database in Android using Jetpack Compose. We have performed different SQL queries for reading and writing our data to SQLite database. In this article, we will take a look at updating data to SQLite database in Android using Jetpack Compose.

Refer to the previous articles to know about how to Create & Add Data and Read Data from SQLite Database.

What we are going to build in this article?

We will be building a simple application in which we were already adding as well as reading the data. Now we will simply update our data in a new activity and we can get to see the updated data. A sample video is given at the end to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Kotlin language.  

Step by Step Implementation

Step 1: Create a New Project in Android Studio

To create a new project in the Android Studio, please refer to How to Create a new Project in Android Studio with Jetpack Compose.

Step 2: Working with DBHandler class

In the previous articles mentioned above, we created a Database Handler Class named DBHandler.kt to handle out database operation. In this step, we will update this class by adding a function updateCourse() to edit our data in a list. The code for the CourseModal.kt is also for convenience.


Step 3: Create a new Activity to update data. 

Navigate to app > kotlin+java > {package-name}, Right click on it, New > Empty Views Activity, name it as UpdateCourse and uncheck the Generate Layout file option. Now add below code to it. Comments are added in the code to get to know in detail. In this file, it be almost as same as the MainActivity except for the text of a button. There will be only one button to update the course. In the next article, we will add a Delete button to delete a data from the database.

UpdateCourse.kt:


Step 4: Update ViewCourses.kt

In this step, we will update the ViewCourses.kt file to add an onClick() to every card to open the UpdateCourse screen. We have already worked on this in the previous article mentioned above. This time we will just an onClick().

ViewCourses.kt:


Step 5: Code for MainActivity.kt

There will be no changes made this time to the MainActivity.kt file. It is only provided for convenience.

MainActivity.kt:

Output:


Comment
Article Tags:

Explore