Professional Documents
Culture Documents
Chapter Six:: Working With Files and Database
Chapter Six:: Working With Files and Database
Damana D.
1
SQLite Database
2
• SQLite used to perform database operations on android
devices such as
– storing,
– manipulating or retrieving persistent data from the database.
• SQLiteOpenHelper class provides the functionality to
use the SQLite database.
3
SQLiteOpenHelper class
4
Constructors of SQLiteOpenHelper class
5
Methods of SQLiteOpenHelper class
void execSQL(String sql) executes the sql query not select query.
long insert(String table, String inserts a record on the database. The table
nullColumnHack, ContentValues values) specifies the table name, nullColumnHack
doesn't allow completely null values. If second
argument is null, android will store null values if
values are empty. The third argument specifies
the values to be stored.
7
Steps to create SQLite Database
• Create a new java class called=DatabaseHelper
• Extend it with SQLiteOpenHelper
• Implement all the methods
• Example table: student
ID Name Mark
1 Ahmed 75
2 Lili 88
3 Beti 65
} 8
Table
• To create a table: use onCreate(….) method
}
9
ContentValues
10
Exercise
11
Thank You
?
12