SQLite CRUD in Android Studio: Insert, Update, Delete and View
Build a small Android app that saves people's details in a local SQLite database, then updates, deletes and lists them. It is the classic first database app: one screen, one helper class, and the four operations every data app needs.
Create a SQLite database and table with SQLiteOpenHelper
Insert, update and delete rows with ContentValues
Read rows with a Cursor and show them in a dialog
Connect buttons in XML to Java code
Before you start
Android Studio (any recent version)
Basic Java: variables, methods and if/else
An emulator or an Android phone
How it fits together
1activity_main.xml form
2MainActivity buttons
3DBHelper methods
4Userdetails table
Build it step by step
1. Create the project
In Android Studio choose New Project → Empty Views Activity. Set Language to Java and Minimum SDK to API 24. If you want to copy the code below without changes, use the package name com.example.sqlitecrud.
2. Build the form
Open activity_main.xml and add three EditText boxes (name, contact, date of birth) and four buttons: Insert, Update, Delete and View. Each view gets an id so Java can find it. The labels live in strings.xml, so the layout stays clean and the app is easy to translate.
3. Create the database helper
Add a new Java class called DBHelper that extends SQLiteOpenHelper.
The constructor names the database file: Userdata.db.
onCreate runs once, the first time the app opens the database, and creates the Userdetails table.
name is the primary key, so two people can't have the same name.
4. Insert a row
insertuserdata puts the three values into a ContentValues object and calls insert. It returns -1 if the row could not be saved, for example when the name already exists.
5. Update and delete
update and delete find the row by name with "name=?". Both return how many rows changed, so 0 means nobody with that name was found.
6. Read everything
getdata runs Select * from Userdetails and returns a Cursor. MainActivity walks through it with moveToNext(), builds one text block, and shows it in an AlertDialog.
7. Connect the buttons
In MainActivity, find each view with findViewById, create one DBHelper, and give every button a click listener that calls the matching method and shows a Toast.
8. Run and test
Insert two people.
Tap View to see them.
Change one person's contact and tap Update.
Delete one and tap View again.
Try inserting the same name twice: you'll see New Entry Not Inserted, because of the primary key.
If something goes wrong
"Entry Not Updated" or "Entry Not Deleted": the name must match exactly, including capital letters.
Where is my data? Open App Inspection → Database Inspector in Android Studio while the app runs, and you can see the Userdetails table live.
The form sits under the status bar: keep the EdgeToEdge and window-insets lines at the top of onCreate.
What's improved over the video
The code matches the video, with three small upgrades: cursors are closed after use, onUpgrade recreates the table, and the screen respects Android 15's edge-to-edge layout.
Files affected
Check what to add and what to replace before copying code.