SlideShare a Scribd company logo
DATABASE IN ANDROID 
FIRST PART
Database Persistence 
If you want the app to remember data between 
sessions, you need to persist the data. 
How? 
You can store your data using a SQLite 
database.
What is SQLite? 
SQLite is a lightweight Database that : 
● Use simple file database to store data. 
● Can use SQL for Database operations. 
● Can manage transactions. 
● Specifications and source code are being published 
● Driver have been developed in many languages.
Start by creating the database 
● Thus, you can create and open database directly inside your app. 
● The best way to get off the ground with a new database is to extend 
a built in abstract base class called SQLiteOpenHelper that provides 
you with all of the basic behavior to manage a database.
Classes provided by Android 
SQLiteHelper Class SQLiteDatabase Class 
Create Database Perform: 
Tables search/ insert/renew/delete 
Create Table 
Perform database connection: Execute the specified SQL- 
(open/close)
The method of Creation DB 
1. Create subclass of SQLiteOpenHelper class.
The method of Creation DB 
2.Execute the constructor of SQLiteOpenHelper class by 
constructor of the class created in 1, create database.
The method of creation DB 
3. Implement 2 methods that are decided by 
SQLiteOpenHelper: 
● onCreate: The method that implements the table creation 
process. 
● onUpgrade: The table that implements the table definition 
renew process.
The method of creation DB 
4. Execute the SQL statement that creates Table at 
SQLiteOpenHelper#onCREATE.
import android.content.Context; 
import android.database.sqlite.SQLiteDatabase; 
import android.database.sqlite.SQLiteOpenHelper; 
import android.util.log; 
public class TrySQLiteOpenHelper extends SQLiteOpenHelper{ 
public trySQLiteOpenHelper(Context context){ 
super(context,”SAMPLE_DATABASE”, null, 1); 
} 
Example:
@override 
Example(continue): 
public void onCreate(SQLiteDatabase database){ 
database.exec.SQL(“CREATE_TABLE_SAMPLE_TABLE 
(-idINTEGER, 
nameTT>T);”); 
} 
Note: 
exec.SQL() executes the optional SQL statement to operate data.
@Override 
Example(continue): 
public void onUpgrade 
(SQLite Database, int old version, int new version){ 
} 
}
Search data from DB 
The mechanism is : 
● Need SQLiteDatabase objects to search data from database. 
● By executing SQLiteDatabase#query method, the results can be 
gotten by Cursor class. 
Note: 
Cursor is the class which represents a 2 dimensional table of any 
database.
Search data from DB 
● Get SQliteOpenDatabase objects by SQLiteOpenHelper method. 
And, depend on uses, There’re 2 methods: 
● getReadableDatabase. 
● getWritableDatabase.
SQLiteDatabase#query method 
● The method of search data: 
1. Create the object of SQLiteOpenHelper class. 
2. Use SQLiteOpenHelper#getReadable Database method to get 
SQLiteDatabase objects. 
3. Execute SQLiteDatabase#query method to get the Cursor objects 
of search results. 
4. Execute Activity#startManagingCursor to transmit Cursor 
management to Activity. 
5. Execute SQLiteDatabase#close method to close database.
TrySQLiteOpenHelper database; 
OpenHelper = new TrySQLiteOpenHelper(this); 
SQLiteDatabase database = null; 
Cursor cursor= null; 
try{ 
// get the SQLiteDatabase objects. 
database = database.OpenHelper.getReadableDatabase(); 
//get the cursor object of searching results. 
cursor = database.query(“SAMPLE_TABLE”,null, null, null, null, 
null); 
Example(query method)
// Transfer the Cursor object management to Activity 
startManagingCursor( cursor); 
}finally{ 
if(database)= null){ 
//disconnect with database 
database.close(); 
} 
} 
Example( query method)

More Related Content

What's hot

Shared preferences
Shared preferencesShared preferences
Shared preferences
Sourabh Sahu
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android
Aakash Ugale
 
Flutter tutorial for Beginner Step by Step
Flutter tutorial for Beginner Step by StepFlutter tutorial for Beginner Step by Step
Flutter tutorial for Beginner Step by Step
Chandramouli Biyyala
 
Android app development ppt
Android app development pptAndroid app development ppt
Android app development ppt
saitej15
 
Creating the first app with android studio
Creating the first app with android studioCreating the first app with android studio
Creating the first app with android studio
Parinita03
 
Android Widget
Android WidgetAndroid Widget
Android Widget
ELLURU Kalyan
 
android layouts
android layoutsandroid layouts
android layoutsDeepa Rani
 
Android architecture
Android architectureAndroid architecture
Android architecture
Kartik Kalpande Patil
 
Android application structure
Android application structureAndroid application structure
Android application structureAlexey Ustenko
 
Android application development ppt
Android application development pptAndroid application development ppt
Android application development ppt
Gautam Kumar
 
android sqlite
android sqliteandroid sqlite
android sqliteDeepa Rani
 
Android Application Development Using Java
Android Application Development Using JavaAndroid Application Development Using Java
Android Application Development Using Java
amaankhan
 
Android resource
Android resourceAndroid resource
Android resourceKrazy Koder
 
Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)Ahsanul Karim
 
Android structure
Android structureAndroid structure
Android structure
Kumar
 
Introduction to Android development - Presentation
Introduction to Android development - PresentationIntroduction to Android development - Presentation
Introduction to Android development - Presentation
Atul Panjwani
 
Activities, Fragments, and Events
Activities, Fragments, and EventsActivities, Fragments, and Events
Activities, Fragments, and Events
Henry Osborne
 
Android UI
Android UIAndroid UI
Android UI
nationalmobileapps
 
Android SDK Tutorial | Edureka
Android SDK Tutorial | EdurekaAndroid SDK Tutorial | Edureka
Android SDK Tutorial | Edureka
Edureka!
 

What's hot (20)

Android Threading
Android ThreadingAndroid Threading
Android Threading
 
Shared preferences
Shared preferencesShared preferences
Shared preferences
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android
 
Flutter tutorial for Beginner Step by Step
Flutter tutorial for Beginner Step by StepFlutter tutorial for Beginner Step by Step
Flutter tutorial for Beginner Step by Step
 
Android app development ppt
Android app development pptAndroid app development ppt
Android app development ppt
 
Creating the first app with android studio
Creating the first app with android studioCreating the first app with android studio
Creating the first app with android studio
 
Android Widget
Android WidgetAndroid Widget
Android Widget
 
android layouts
android layoutsandroid layouts
android layouts
 
Android architecture
Android architectureAndroid architecture
Android architecture
 
Android application structure
Android application structureAndroid application structure
Android application structure
 
Android application development ppt
Android application development pptAndroid application development ppt
Android application development ppt
 
android sqlite
android sqliteandroid sqlite
android sqlite
 
Android Application Development Using Java
Android Application Development Using JavaAndroid Application Development Using Java
Android Application Development Using Java
 
Android resource
Android resourceAndroid resource
Android resource
 
Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)
 
Android structure
Android structureAndroid structure
Android structure
 
Introduction to Android development - Presentation
Introduction to Android development - PresentationIntroduction to Android development - Presentation
Introduction to Android development - Presentation
 
Activities, Fragments, and Events
Activities, Fragments, and EventsActivities, Fragments, and Events
Activities, Fragments, and Events
 
Android UI
Android UIAndroid UI
Android UI
 
Android SDK Tutorial | Edureka
Android SDK Tutorial | EdurekaAndroid SDK Tutorial | Edureka
Android SDK Tutorial | Edureka
 

Viewers also liked

ANDROID USING SQLITE DATABASE ADMINISTRATORS ~HMFTJ
ANDROID USING SQLITE DATABASE ADMINISTRATORS ~HMFTJANDROID USING SQLITE DATABASE ADMINISTRATORS ~HMFTJ
ANDROID USING SQLITE DATABASE ADMINISTRATORS ~HMFTJ
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
Android vs iOS
Android vs iOSAndroid vs iOS
Android vs iOS
Katsuya Goto
 
Data Handning with Sqlite for Android
Data Handning with Sqlite for AndroidData Handning with Sqlite for Android
Data Handning with Sqlite for AndroidJakir Hossain
 
Android Protips: Advanced Topics for Expert Android App Developers
Android Protips: Advanced Topics for Expert Android App DevelopersAndroid Protips: Advanced Topics for Expert Android App Developers
Android Protips: Advanced Topics for Expert Android App Developers
Reto Meier
 
Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)
Khaled Anaqwa
 
09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)
Oum Saokosal
 
Design and Concepts of Android Graphics
Design and Concepts of Android GraphicsDesign and Concepts of Android Graphics
Design and Concepts of Android Graphics
National Cheng Kung University
 
Android database tutorial
Android database tutorialAndroid database tutorial
Android database tutorial
info_zybotech
 

Viewers also liked (9)

ANDROID USING SQLITE DATABASE ADMINISTRATORS ~HMFTJ
ANDROID USING SQLITE DATABASE ADMINISTRATORS ~HMFTJANDROID USING SQLITE DATABASE ADMINISTRATORS ~HMFTJ
ANDROID USING SQLITE DATABASE ADMINISTRATORS ~HMFTJ
 
Android Database
Android DatabaseAndroid Database
Android Database
 
Android vs iOS
Android vs iOSAndroid vs iOS
Android vs iOS
 
Data Handning with Sqlite for Android
Data Handning with Sqlite for AndroidData Handning with Sqlite for Android
Data Handning with Sqlite for Android
 
Android Protips: Advanced Topics for Expert Android App Developers
Android Protips: Advanced Topics for Expert Android App DevelopersAndroid Protips: Advanced Topics for Expert Android App Developers
Android Protips: Advanced Topics for Expert Android App Developers
 
Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)
 
09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)
 
Design and Concepts of Android Graphics
Design and Concepts of Android GraphicsDesign and Concepts of Android Graphics
Design and Concepts of Android Graphics
 
Android database tutorial
Android database tutorialAndroid database tutorial
Android database tutorial
 

Similar to Database in Android

Create an android app for database creation using.pptx
Create an android app for database creation using.pptxCreate an android app for database creation using.pptx
Create an android app for database creation using.pptx
vishal choudhary
 
Android App Development 05 : Saving Data
Android App Development 05 : Saving DataAndroid App Development 05 : Saving Data
Android App Development 05 : Saving DataAnuchit Chalothorn
 
Android sq lite-chapter 22
Android sq lite-chapter 22Android sq lite-chapter 22
Android sq lite-chapter 22
Dr. Ramkumar Lakshminarayanan
 
Sql lite android
Sql lite androidSql lite android
Sql lite android
Dushyant Nasit
 
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
TAISEEREISA
 
Notepad tutorial
Notepad tutorialNotepad tutorial
Notepad tutorial
info_zybotech
 
Sql server 2012 tutorials writing transact-sql statements
Sql server 2012 tutorials   writing transact-sql statementsSql server 2012 tutorials   writing transact-sql statements
Sql server 2012 tutorials writing transact-sql statementsSteve Xu
 
Android sql examples
Android sql examplesAndroid sql examples
Android sql examples
Aravindharamanan S
 
How to use sq lite with java using net beans
How to use sq lite with java using net beansHow to use sq lite with java using net beans
How to use sq lite with java using net beans
Aravindharamanan S
 
Chapter -7.pptx
Chapter -7.pptxChapter -7.pptx
Chapter -7.pptx
MikialeTesfamariam
 
Sq lite
Sq liteSq lite
Sq lite
vinoth raj
 
9 content-providers
9 content-providers9 content-providers
9 content-providers
Aravindharamanan S
 
Migrating from PHP 4 to PHP 5
Migrating from PHP 4 to PHP 5Migrating from PHP 4 to PHP 5
Migrating from PHP 4 to PHP 5
John Coggeshall
 
12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptx12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptx
FaezNasir
 
I am looking for some assistance with SQLite database. I have tried se.pdf
I am looking for some assistance with SQLite database. I have tried se.pdfI am looking for some assistance with SQLite database. I have tried se.pdf
I am looking for some assistance with SQLite database. I have tried se.pdf
Conint29
 
Accessing data with android cursors
Accessing data with android cursorsAccessing data with android cursors
Accessing data with android cursors
info_zybotech
 
Accessing data with android cursors
Accessing data with android cursorsAccessing data with android cursors
Accessing data with android cursors
info_zybotech
 
SQLite in Flutter.pptx
SQLite in Flutter.pptxSQLite in Flutter.pptx
SQLite in Flutter.pptx
Nabin Dhakal
 
Asp .Net Database Connectivity Presentation.pptx
Asp .Net Database Connectivity Presentation.pptxAsp .Net Database Connectivity Presentation.pptx
Asp .Net Database Connectivity Presentation.pptx
sridharu1981
 
unit 3.docx
unit 3.docxunit 3.docx
unit 3.docx
Sadhana Sreekanth
 

Similar to Database in Android (20)

Create an android app for database creation using.pptx
Create an android app for database creation using.pptxCreate an android app for database creation using.pptx
Create an android app for database creation using.pptx
 
Android App Development 05 : Saving Data
Android App Development 05 : Saving DataAndroid App Development 05 : Saving Data
Android App Development 05 : Saving Data
 
Android sq lite-chapter 22
Android sq lite-chapter 22Android sq lite-chapter 22
Android sq lite-chapter 22
 
Sql lite android
Sql lite androidSql lite android
Sql lite android
 
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
 
Notepad tutorial
Notepad tutorialNotepad tutorial
Notepad tutorial
 
Sql server 2012 tutorials writing transact-sql statements
Sql server 2012 tutorials   writing transact-sql statementsSql server 2012 tutorials   writing transact-sql statements
Sql server 2012 tutorials writing transact-sql statements
 
Android sql examples
Android sql examplesAndroid sql examples
Android sql examples
 
How to use sq lite with java using net beans
How to use sq lite with java using net beansHow to use sq lite with java using net beans
How to use sq lite with java using net beans
 
Chapter -7.pptx
Chapter -7.pptxChapter -7.pptx
Chapter -7.pptx
 
Sq lite
Sq liteSq lite
Sq lite
 
9 content-providers
9 content-providers9 content-providers
9 content-providers
 
Migrating from PHP 4 to PHP 5
Migrating from PHP 4 to PHP 5Migrating from PHP 4 to PHP 5
Migrating from PHP 4 to PHP 5
 
12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptx12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptx
 
I am looking for some assistance with SQLite database. I have tried se.pdf
I am looking for some assistance with SQLite database. I have tried se.pdfI am looking for some assistance with SQLite database. I have tried se.pdf
I am looking for some assistance with SQLite database. I have tried se.pdf
 
Accessing data with android cursors
Accessing data with android cursorsAccessing data with android cursors
Accessing data with android cursors
 
Accessing data with android cursors
Accessing data with android cursorsAccessing data with android cursors
Accessing data with android cursors
 
SQLite in Flutter.pptx
SQLite in Flutter.pptxSQLite in Flutter.pptx
SQLite in Flutter.pptx
 
Asp .Net Database Connectivity Presentation.pptx
Asp .Net Database Connectivity Presentation.pptxAsp .Net Database Connectivity Presentation.pptx
Asp .Net Database Connectivity Presentation.pptx
 
unit 3.docx
unit 3.docxunit 3.docx
unit 3.docx
 

More from MaryadelMar85

gvSIG visualización y navegación
gvSIG visualización y navegacióngvSIG visualización y navegación
gvSIG visualización y navegación
MaryadelMar85
 
gvSIG: Proyectos y Documentos
gvSIG: Proyectos y DocumentosgvSIG: Proyectos y Documentos
gvSIG: Proyectos y Documentos
MaryadelMar85
 
Conceptos Básicos en gvSIG
Conceptos Básicos en gvSIGConceptos Básicos en gvSIG
Conceptos Básicos en gvSIG
MaryadelMar85
 
Definición e Instalación de gvSIG
Definición e Instalación de gvSIGDefinición e Instalación de gvSIG
Definición e Instalación de gvSIG
MaryadelMar85
 
android:versionName and android:versionCode
android:versionName and  android:versionCodeandroid:versionName and  android:versionCode
android:versionName and android:versionCode
MaryadelMar85
 
Eclipse in Android. 3 common issues.
Eclipse in Android. 3 common issues.Eclipse in Android. 3 common issues.
Eclipse in Android. 3 common issues.
MaryadelMar85
 
Intents and PendingIntents in Android application development
Intents and PendingIntents in Android application developmentIntents and PendingIntents in Android application development
Intents and PendingIntents in Android application development
MaryadelMar85
 

More from MaryadelMar85 (7)

gvSIG visualización y navegación
gvSIG visualización y navegacióngvSIG visualización y navegación
gvSIG visualización y navegación
 
gvSIG: Proyectos y Documentos
gvSIG: Proyectos y DocumentosgvSIG: Proyectos y Documentos
gvSIG: Proyectos y Documentos
 
Conceptos Básicos en gvSIG
Conceptos Básicos en gvSIGConceptos Básicos en gvSIG
Conceptos Básicos en gvSIG
 
Definición e Instalación de gvSIG
Definición e Instalación de gvSIGDefinición e Instalación de gvSIG
Definición e Instalación de gvSIG
 
android:versionName and android:versionCode
android:versionName and  android:versionCodeandroid:versionName and  android:versionCode
android:versionName and android:versionCode
 
Eclipse in Android. 3 common issues.
Eclipse in Android. 3 common issues.Eclipse in Android. 3 common issues.
Eclipse in Android. 3 common issues.
 
Intents and PendingIntents in Android application development
Intents and PendingIntents in Android application developmentIntents and PendingIntents in Android application development
Intents and PendingIntents in Android application development
 

Recently uploaded

To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 

Recently uploaded (20)

To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 

Database in Android

  • 1. DATABASE IN ANDROID FIRST PART
  • 2. Database Persistence If you want the app to remember data between sessions, you need to persist the data. How? You can store your data using a SQLite database.
  • 3. What is SQLite? SQLite is a lightweight Database that : ● Use simple file database to store data. ● Can use SQL for Database operations. ● Can manage transactions. ● Specifications and source code are being published ● Driver have been developed in many languages.
  • 4. Start by creating the database ● Thus, you can create and open database directly inside your app. ● The best way to get off the ground with a new database is to extend a built in abstract base class called SQLiteOpenHelper that provides you with all of the basic behavior to manage a database.
  • 5. Classes provided by Android SQLiteHelper Class SQLiteDatabase Class Create Database Perform: Tables search/ insert/renew/delete Create Table Perform database connection: Execute the specified SQL- (open/close)
  • 6. The method of Creation DB 1. Create subclass of SQLiteOpenHelper class.
  • 7. The method of Creation DB 2.Execute the constructor of SQLiteOpenHelper class by constructor of the class created in 1, create database.
  • 8. The method of creation DB 3. Implement 2 methods that are decided by SQLiteOpenHelper: ● onCreate: The method that implements the table creation process. ● onUpgrade: The table that implements the table definition renew process.
  • 9. The method of creation DB 4. Execute the SQL statement that creates Table at SQLiteOpenHelper#onCREATE.
  • 10. import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.util.log; public class TrySQLiteOpenHelper extends SQLiteOpenHelper{ public trySQLiteOpenHelper(Context context){ super(context,”SAMPLE_DATABASE”, null, 1); } Example:
  • 11. @override Example(continue): public void onCreate(SQLiteDatabase database){ database.exec.SQL(“CREATE_TABLE_SAMPLE_TABLE (-idINTEGER, nameTT>T);”); } Note: exec.SQL() executes the optional SQL statement to operate data.
  • 12. @Override Example(continue): public void onUpgrade (SQLite Database, int old version, int new version){ } }
  • 13. Search data from DB The mechanism is : ● Need SQLiteDatabase objects to search data from database. ● By executing SQLiteDatabase#query method, the results can be gotten by Cursor class. Note: Cursor is the class which represents a 2 dimensional table of any database.
  • 14. Search data from DB ● Get SQliteOpenDatabase objects by SQLiteOpenHelper method. And, depend on uses, There’re 2 methods: ● getReadableDatabase. ● getWritableDatabase.
  • 15. SQLiteDatabase#query method ● The method of search data: 1. Create the object of SQLiteOpenHelper class. 2. Use SQLiteOpenHelper#getReadable Database method to get SQLiteDatabase objects. 3. Execute SQLiteDatabase#query method to get the Cursor objects of search results. 4. Execute Activity#startManagingCursor to transmit Cursor management to Activity. 5. Execute SQLiteDatabase#close method to close database.
  • 16. TrySQLiteOpenHelper database; OpenHelper = new TrySQLiteOpenHelper(this); SQLiteDatabase database = null; Cursor cursor= null; try{ // get the SQLiteDatabase objects. database = database.OpenHelper.getReadableDatabase(); //get the cursor object of searching results. cursor = database.query(“SAMPLE_TABLE”,null, null, null, null, null); Example(query method)
  • 17. // Transfer the Cursor object management to Activity startManagingCursor( cursor); }finally{ if(database)= null){ //disconnect with database database.close(); } } Example( query method)