SQLite-Database-Tutorial 9117876 Powerpoint
SQLite-Database-Tutorial 9117876 Powerpoint
SQLite Database in Android used to s tore persistent data. If you want to s tore some data into local s torage then
SQLite Database is the most common s torage option. It is lightweight database that comes with Android OS.
In Android There are others data s torage options also available Like
Here we are going to learn how to use SQLite Database in Android application. SQLite is an open source SQL database
which s tore the data into text le on android device. SQLite database in android also support relational database features.
In order to access SQLite Database you don’t need to establish any kind of connections like J DBC, ODBC.
1. Overview
In this tutorial we are going to create Student App to learn all the operation related the SQLite Database. The app is
very s imple and which allow us to insert, update, delete and view s tudent data. We will use 2 screen to perform all
this
operations. In rs t screen we fetch full lis t of s tudent from the s tudent table while using second screen update or add
new s tudent record.
1.Create a new project in Android Studio from File ⇒ New Project and select Basic Activity from the templates.
2.Open build.gradle under app directory and add CardView library. CardView is used to display Student List inside the
Card.
1 dependencies {
2 //...
3
4 implementa
5 tion
6 'com.androi
7 d.support:c
8 ardview-
v7:27.1.1'
//...
3. Add following code into colors.xml and strings.xml files.
}
colors.xml
c ol o r s . xm l
strings.xml
1 <resources>
2 <string name="app_name">Student Management</string>
3 <string name="strAddNewStudent">Add New Student</string>
4 <string name="strUpdateStudent">Update Student</string>
5 <string name="strDelete">Delete</string>
6 <string name="strStudentName">Enter Student Name</string>
7 <string name="strStudentResult">Enter Pass/Fail</string>
8 <string name="strStudentGrade">Enter Grade</string>
9 <string name="strSave">Save</string>
10 </resources>
4. Create following packages named adapter, db, model and ui. The following is the final project structure and files
are required.
5. In this tutorial we have taken student example to perform all operation. So first we need to create one model
class named StudentInfo.java under model package. StudentInfo.java contain student information like id, name,
grade and result. Further we will used this class to store and retrieve student information from the SQLite
database.
Stud entInfo.java
6. Now we need to create a class that extends from SQLiteOpenHelper. So create DBHelper.java under db package.
DBHelper.java perform all the database operations like Create, Update, Delete and Read.
Before the proceed let’s understand use of all the methods and table structure of the StudentInfo.
onCreate() method will be called only once when application launch first time in android phone. So from this
method we will execute sql statement to create Student table.
onUpgrade() method will be called when update the application. You need to change the DB_VERSION in order
to execute this methods.
The StudentInfo table needs four column : _id, name, result and grade.
Column _id is declared as Primary Key and Auto Increment which means it is unique key to identify the
Students.
name contains student name, result is ether pass or fail, grade contains student grade.