SQLite Database and Database Creation &
Connection in Android
SQLite is a lightweight, open-source relational database built into Android. It is used to store and
manage structured data locally on a device and supports SQL operations such as CREATE,
INSERT, SELECT, UPDATE, and DELETE.
Features of SQLite
• Lightweight and fast
• Serverless database
• Stores data locally
• Supports SQL queries
• Reliable and secure
• Built into Android
Database Creation Using SQLiteOpenHelper
Create a helper class extending SQLiteOpenHelper. The onCreate() method creates tables and
onUpgrade() handles database version changes.
public class DBHelper extends SQLiteOpenHelper {
public DBHelper(Context context) {
super(context, "StudentDB", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
[Link]("CREATE TABLE Student(id INTEGER PRIMARY KEY, name TEXT)");
}
}
Database Connection
Writable Database:
SQLiteDatabase db = [Link]();
Readable Database:
SQLiteDatabase db = [Link]();
CRUD Operations
INSERT INTO Student VALUES(1,'Ali');
SELECT * FROM Student;
UPDATE Student SET name='Ahmed' WHERE id=1;
DELETE FROM Student WHERE id=1;
Advantages
• Lightweight and efficient
• No server required
• Easy integration with Android
• Suitable for offline applications
Conclusion
SQLite is the default relational database in Android. Database creation is done using
SQLiteOpenHelper and connections are established using getWritableDatabase() or
getReadableDatabase(). It supports complete CRUD operations and is widely used in Android
applications.