Sqlite Multiple Table
-
Upload
danang-kukuh-pribadi -
Category
Education
-
view
1.400 -
download
1
description
Transcript of Sqlite Multiple Table
Think AndroidLesson : Sqlite Multiple Tables
By : Danang Kukuh P
What is Sqlite? SQLite is an Open Source database. SQLite supports
standard relational database features like SQL syntax, transactions and prepared statements.
Sqlite in Android SQLite is embedded into every Android device. Using an
SQLite database in Android does not require a setup procedure or administration of the database.
You only have to define the SQL statements for creating and updating the database. Afterwards the database is automatically managed for you by the Android platform.
Sqlite Multiple Tables I explained how to use SQLite database in your android
application. But that covered the scenario, only when you have one table in the database. I am getting lot of queries about handling the sqlite database when it is having multiple tables.
Introduction to the project
Database Design
FIELD TYPE KEY
Id INTEGER PK
Name TEXT
created_at DATETIME
Film Kategori
FIELD TYPE KEY
Id INTEGER PK
name TEXT
created_at DATETIME
FIELD TYPE KEY
Id INTEGER PK
Film_id INTEGER
Kategori_id INTEGER
Film_kategori
Example Data
Id Name
1 Ketika Jomblo Bertasbih
2 Petualangan si gundul
3 Transformer
4 Sadako
5 3 Hati 2 Dunia 1 Cinta
Id Name
1 Action
2 Horror
3 Adventure
4 Drama
Id Film_id Kategori_id
1 1 4
2 2 3
3 3 1
4 4 2
5 5 4
Film Kategori
Film_Kategori
Let’s Start a New Project Click New in the toolbar. In the window that appears,
open the Android folder,
select Android Application
Project,
and click Next. Figure 1.
The New Android App
Project wizard in Eclipse.
Creating Model Class for Tables Create Class Film.java and Kategori.java in package model
And create constructor, setter and getter
Creating DatabaseHelper Create Class DatabaseHelper.java in package helper And create CRUD(Create, Read, Update, Delete) Operations
MainActivity In the below I just created sample Kategori and Film data
and performed the all the operations by calling the methods which we prepared in DatabaseHelper class.
Run App….Check data in Database I Check data in Database Sqlite with Sqlite Editor
Source Code? Check Source Code in My GitHub https://github.com/dpapayas/SqliteMultipleTables
Thanks