O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Sqlite Multiple Table

3.432 visualizações

Publicada em

Publicada em: Educação
  • Entre para ver os comentários

Sqlite Multiple Table

  1. 1. Think Android Lesson : Sqlite Multiple Tables By : Danang Kukuh P
  2. 2. What is Sqlite?  SQLite is an Open Source database. SQLite supports standard relational database features like SQL syntax, transactions and prepared statements.
  3. 3. 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.
  4. 4. 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.
  5. 5. Introduction to the project Database Design Film Kategori FIELD TYPE KEY FIELD TYPE Id INTEGER PK Id INTEGER PK Name TEXT name TEXT created_at DATETIME created_at DATETIME Film_kategori FIELD TYPE KEY Id INTEGER PK Film_id INTEGER Kategori_id INTEGER KEY
  6. 6. Example Data Kategori Film Id Name Id Name 1 Ketika Jomblo Bertasbih 1 Action 2 Petualangan si gundul 2 Horror 3 Transformer 3 Adventure 4 Sadako 4 Drama 5 3 Hati 2 Dunia 1 Cinta Film_Kategori Id 1 Film_id 1 Kategori_id 4 2 2 3 3 3 1 4 4 2 5 5 4
  7. 7. 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.
  8. 8. Creating Model Class for Tables  Create Class Film.java and Kategori.java in package model And create constructor, setter and getter
  9. 9. Creating DatabaseHelper  Create Class DatabaseHelper.java in package helper  And create CRUD(Create, Read, Update, Delete) Operations
  10. 10. 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.
  11. 11. Run App…. Check data in Database  I Check data in Database Sqlite with Sqlite Editor
  12. 12. Source Code?  Check Source Code in My GitHub  https://github.com/dpapayas/SqliteMultipleTables
  13. 13. Thanks 