SlideShare a Scribd company logo
09.1. Database
Oum Saokosal
Master of Engineering in Information Systems, South Korea
855-12-252-752
oum_saokosal@yahoo.com
SQLite
• SQLite is popular light-weight database
• For Android, SQLite is "baked into" the
Android runtime, so every Android application
can create SQLite databases.
Fundamental of SQL
• Create a table:
CREATE TABLE IF NOT EXISTS tbl_student (
stu_id INTEGER PRIMARY KEY AUTOINCREMENT,
stu_name VARCHAR(50) NULL,
stu_add VARCHAR(100) NULL,
stu_gpa FLOAT NULL
);
• Insert a record:
INSERT INTO tbl_student VALUES (
80123,
'Sok Visal',
'Phnom Penh',
4.0
);
• Select a record:
SELECT *
FROM tbl_student
WHERE stu_id=80123
ORDER BY stu_name ASC
• View many records:
SELECT *
FROM tbl_student
WHERE stu_name LIKE '%sok%'
ORDER BY stu_name DESC
• Update a record:
UPDATE tbl_student
SET stu_name='Sok Visal',
stu_add='Takeo', stu_gpa=4.0
WHERE stu_id = 80123;
• Delete a record:
DELETE FROM tbl_student
WHERE stu_id=80123;
SQLite Statements
• To Create a database:
SQLiteDatabase db = openOrCreateDatabase(
"database_name", MODE_PRIVATE, null);
• To execute a raw SQL statement:
db.execSQL("CREATE TABLE tbl_product (pro_id
integer, pro_name nvarchar(50));");
• To close a database:
db.close();
• To create a table by executing a raw SQL
statement:
db.execSQL("CREATE TABLE IF NOT EXISTS tbl_student
(stu_id INT PRIMARY KEY AUTOINCREMENT,
stu_name VARCHAR(50) NULL,
stu_add VARCHAR(100) NULL,
stu_gpa FLOAT);");
• Insert a record:
db.execSQL("INSERT INTO tbl_student
VALUES (80123, 'Sok Visal',
'Phnom Penh', 4.0);");
• Update a record:
db.execSQL("UPDATE tbl_student
SET stu_name='Sok Visal',
stu_add='Takeo', stu_gpa=4.0
WHERE stu_id = 80123;");
• Delete a record:
db.execSQL("DELETE FROM tbl_student
WHERE stu_id= 80123;");
Records Retrieval
• After you select records using SELECT, you need
to display it. In Android, you will use Cursor class
to store the records.
Cursor result = db.rawQuery("SELECT * FROM
tbl_student WHERE stu_id=80123
ORDER BY stu_name ASC", null);
• Complete code of records retrieval:
Cursor result = db.rawQuery("SELECT * FROM tbl_student
WHERE stu_id=80123 ORDER BY stu_name ASC", null);
result.moveToFirst(); //Must include this
while(result.isAfterLast() != true){
int id = result.getInt(0);
String name = result.getString(1);
String address = result.getString(2);
int gpa = result.getFloat(3);
//Do something here
result.moveToNext();
}
Where is My Database?
• Please note that to see the database folder, you
need to run the emulator first.
• After created a database, you can find it by going
to DDMS -> File Explorer -> Then open the folder:
data/data/your.app.package/databases/yourdbname
09.1. Android - Local Database (Sqlite)
How to View My Database?
• There is a plugin that allows you to view SQLite file in Eclipse.
Below is the url:
http://www.tylerfrankenstein.com/user/4/browse-android-
emulator-sqlite-database-eclipse
• After you download it onto your machine, place it here:
How to View My Database? Cont.
Project Assignment
• Think of your own favorite project related to a
database and intent. And then make it a nice
App for Android.
Go on to the next slide

More Related Content

PPTX
Database in Android
MaryadelMar85
 
DOCX
Android database tutorial
info_zybotech
 
PPTX
Android Database
Rashad Aliyev
 
PPTX
Databases in Android Application
Mark Lester Navarro
 
PPT
SQLITE Android
Sourabh Sahu
 
PPTX
Android Training (Storing data using SQLite)
Khaled Anaqwa
 
PPTX
android sqlite
Deepa Rani
 
PDF
SQLite Database Tutorial In Android
Android 5
 
Database in Android
MaryadelMar85
 
Android database tutorial
info_zybotech
 
Android Database
Rashad Aliyev
 
Databases in Android Application
Mark Lester Navarro
 
SQLITE Android
Sourabh Sahu
 
Android Training (Storing data using SQLite)
Khaled Anaqwa
 
android sqlite
Deepa Rani
 
SQLite Database Tutorial In Android
Android 5
 

What's hot (20)

PPTX
Android Database Tutorial
Perfect APK
 
DOCX
ANDROID USING SQLITE DATABASE ADMINISTRATORS ~HMFTJ
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
PDF
Persitance Data with sqlite
Arif Huda
 
ODP
Sql lite android
Dushyant Nasit
 
PPTX
07.3. Android Alert message, List, Dropdown, and Auto Complete
Oum Saokosal
 
PPTX
Data Handning with Sqlite for Android
Jakir Hossain
 
PPTX
SQLite database in android
Gourav Kumar Saini
 
PPTX
Database
nationalmobileapps
 
PDF
Android datastorage
Krazy Koder
 
PDF
Android App Development 05 : Saving Data
Anuchit Chalothorn
 
PDF
Advanced Core Data
Make School
 
DOCX
Accessing data with android cursors
info_zybotech
 
PPTX
Using sqlite database in android with sqlite manager browser add ons
Vincent Clyde
 
DOCX
Android sq lite-chapter 22
Dr. Ramkumar Lakshminarayanan
 
PDF
Dicoding Developer Coaching #19: Android | Menyimpan Database Secara Local di...
DicodingEvent
 
PDF
Persistence on iOS
Make School
 
PPTX
Database Programming
Henry Osborne
 
PDF
Introduction to SQLite: The Most Popular Database in the World
jkreibich
 
PDF
Dicoding Developer Coaching #32: Android | Reactive Programming dengan RxJava...
DicodingEvent
 
PPTX
Entity Framework Database and Code First
James Johnson
 
Android Database Tutorial
Perfect APK
 
ANDROID USING SQLITE DATABASE ADMINISTRATORS ~HMFTJ
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
Persitance Data with sqlite
Arif Huda
 
Sql lite android
Dushyant Nasit
 
07.3. Android Alert message, List, Dropdown, and Auto Complete
Oum Saokosal
 
Data Handning with Sqlite for Android
Jakir Hossain
 
SQLite database in android
Gourav Kumar Saini
 
Android datastorage
Krazy Koder
 
Android App Development 05 : Saving Data
Anuchit Chalothorn
 
Advanced Core Data
Make School
 
Accessing data with android cursors
info_zybotech
 
Using sqlite database in android with sqlite manager browser add ons
Vincent Clyde
 
Android sq lite-chapter 22
Dr. Ramkumar Lakshminarayanan
 
Dicoding Developer Coaching #19: Android | Menyimpan Database Secara Local di...
DicodingEvent
 
Persistence on iOS
Make School
 
Database Programming
Henry Osborne
 
Introduction to SQLite: The Most Popular Database in the World
jkreibich
 
Dicoding Developer Coaching #32: Android | Reactive Programming dengan RxJava...
DicodingEvent
 
Entity Framework Database and Code First
James Johnson
 
Ad

Viewers also liked (20)

PPT
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Oum Saokosal
 
PPTX
10.3 Android Video
Oum Saokosal
 
PPTX
11.1 Android with HTML
Oum Saokosal
 
PPT
Java Programming - Polymorphism
Oum Saokosal
 
PPT
Objected-Oriented Programming with Java
Oum Saokosal
 
PDF
[2C6]SQLite DB 의 입출력 특성분석 : Android 와 Tizen 사례
NAVER D2
 
PPT
Java Programming - Introduction to Abstract Class
Oum Saokosal
 
PPT
Java Programming - Inheritance
Oum Saokosal
 
PPTX
Database Concept - ERD Mapping to MS Access
Oum Saokosal
 
PPTX
Database Concept - Normalization (1NF, 2NF, 3NF)
Oum Saokosal
 
PPT
Java Programming - Abstract Class and Interface
Oum Saokosal
 
PPTX
SQLite: Light, Open Source Relational Database Management System
Tanner Jessel
 
PPTX
Android - Introduction
Oum Saokosal
 
PDF
Android development beyond the basics
Vanjikumaran Sivajothy
 
PPTX
Sq lite
RAUL Velez
 
PPTX
SQLite
Edniizz Quisol
 
DOCX
Android de la A a la Z - Unidad 7
Jorge Ulises
 
PDF
Aula 06 - TEP - Introdução SQLite
Anderson Fabiano Dums
 
PPTX
07.4. Android Basic Simple Browser (WebView)
Oum Saokosal
 
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Oum Saokosal
 
10.3 Android Video
Oum Saokosal
 
11.1 Android with HTML
Oum Saokosal
 
Java Programming - Polymorphism
Oum Saokosal
 
Objected-Oriented Programming with Java
Oum Saokosal
 
[2C6]SQLite DB 의 입출력 특성분석 : Android 와 Tizen 사례
NAVER D2
 
Java Programming - Introduction to Abstract Class
Oum Saokosal
 
Java Programming - Inheritance
Oum Saokosal
 
Database Concept - ERD Mapping to MS Access
Oum Saokosal
 
Database Concept - Normalization (1NF, 2NF, 3NF)
Oum Saokosal
 
Java Programming - Abstract Class and Interface
Oum Saokosal
 
SQLite: Light, Open Source Relational Database Management System
Tanner Jessel
 
Android - Introduction
Oum Saokosal
 
Android development beyond the basics
Vanjikumaran Sivajothy
 
Sq lite
RAUL Velez
 
Android de la A a la Z - Unidad 7
Jorge Ulises
 
Aula 06 - TEP - Introdução SQLite
Anderson Fabiano Dums
 
07.4. Android Basic Simple Browser (WebView)
Oum Saokosal
 
Ad

Similar to 09.1. Android - Local Database (Sqlite) (20)

PDF
Java OOP Programming language (Part 8) - Java Database JDBC
OUM SAOKOSAL
 
PPTX
Python SQLite3...
VikasTuwar1
 
PPTX
Oracle Database 12c - New Features for Developers and DBAs
Alex Zaballa
 
PPTX
Oracle Database 12c - New Features for Developers and DBAs
Alex Zaballa
 
PDF
04. SQL Servesdafr with CSharp WinForms.pdf
ManhHoangVan
 
PPTX
Introduction to database
Pongsakorn U-chupala
 
PDF
DEF CON 27 -OMER GULL - select code execution from using sq lite
Felipe Prado
 
PDF
M.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMS
Supriya Radhakrishna
 
POTX
Oracle vs. SQL Server- War of the Indices
Kellyn Pot'Vin-Gorman
 
PDF
Oracle Material.pdf
rajeshkathavarayan
 
PDF
Avoiding cursors with sql server 2005 tech republic
Kaing Menglieng
 
PDF
Cassandra Day Chicago 2015: Apache Cassandra Data Modeling 101
DataStax Academy
 
PDF
Cassandra Day London 2015: Data Modeling 101
DataStax Academy
 
PDF
Cassandra Day Atlanta 2015: Data Modeling 101
DataStax Academy
 
PPT
FMDB - SLC-Cocoaheads
Dave Stevenson
 
PPTX
53 SQL Questions-Answers12121212121212.pptx
Ganesh Shirsat
 
PPTX
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
TAISEEREISA
 
PPTX
Do You Have the Time
Michael Antonovich
 
PPTX
53 SQL Questions-Answers=53 SQL Questions-Answers
marukochan23
 
PPT
Android SQLite database oriented application development
Kongu Engineering College, Perundurai, Erode
 
Java OOP Programming language (Part 8) - Java Database JDBC
OUM SAOKOSAL
 
Python SQLite3...
VikasTuwar1
 
Oracle Database 12c - New Features for Developers and DBAs
Alex Zaballa
 
Oracle Database 12c - New Features for Developers and DBAs
Alex Zaballa
 
04. SQL Servesdafr with CSharp WinForms.pdf
ManhHoangVan
 
Introduction to database
Pongsakorn U-chupala
 
DEF CON 27 -OMER GULL - select code execution from using sq lite
Felipe Prado
 
M.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMS
Supriya Radhakrishna
 
Oracle vs. SQL Server- War of the Indices
Kellyn Pot'Vin-Gorman
 
Oracle Material.pdf
rajeshkathavarayan
 
Avoiding cursors with sql server 2005 tech republic
Kaing Menglieng
 
Cassandra Day Chicago 2015: Apache Cassandra Data Modeling 101
DataStax Academy
 
Cassandra Day London 2015: Data Modeling 101
DataStax Academy
 
Cassandra Day Atlanta 2015: Data Modeling 101
DataStax Academy
 
FMDB - SLC-Cocoaheads
Dave Stevenson
 
53 SQL Questions-Answers12121212121212.pptx
Ganesh Shirsat
 
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
TAISEEREISA
 
Do You Have the Time
Michael Antonovich
 
53 SQL Questions-Answers=53 SQL Questions-Answers
marukochan23
 
Android SQLite database oriented application development
Kongu Engineering College, Perundurai, Erode
 

More from Oum Saokosal (12)

PPTX
12. Android Basic Google Map
Oum Saokosal
 
PPTX
10.2 Android Audio with SD Card
Oum Saokosal
 
PPTX
10.1. Android Audio
Oum Saokosal
 
PPTX
08.1. Android How to Use Intent (explicit)
Oum Saokosal
 
PPTX
07.1. Android Even Handling
Oum Saokosal
 
PPTX
06. Android Basic Widget and Container
Oum Saokosal
 
PPTX
More on Application Structure
Oum Saokosal
 
PPTX
04. Review OOP with Java
Oum Saokosal
 
PPTX
Basic Understanding of Android XML
Oum Saokosal
 
PPTX
02.1 - Getting Started with Android
Oum Saokosal
 
PPTX
Introduction to Android
Oum Saokosal
 
DOCX
Using intents in android
Oum Saokosal
 
12. Android Basic Google Map
Oum Saokosal
 
10.2 Android Audio with SD Card
Oum Saokosal
 
10.1. Android Audio
Oum Saokosal
 
08.1. Android How to Use Intent (explicit)
Oum Saokosal
 
07.1. Android Even Handling
Oum Saokosal
 
06. Android Basic Widget and Container
Oum Saokosal
 
More on Application Structure
Oum Saokosal
 
04. Review OOP with Java
Oum Saokosal
 
Basic Understanding of Android XML
Oum Saokosal
 
02.1 - Getting Started with Android
Oum Saokosal
 
Introduction to Android
Oum Saokosal
 
Using intents in android
Oum Saokosal
 

Recently uploaded (20)

PPT
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
PPTX
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
PDF
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
PPTX
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
PPTX
Understanding operators in c language.pptx
auteharshil95
 
PDF
7.Particulate-Nature-of-Matter.ppt/8th class science curiosity/by k sandeep s...
Sandeep Swamy
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PDF
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
PDF
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
PDF
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
Understanding operators in c language.pptx
auteharshil95
 
7.Particulate-Nature-of-Matter.ppt/8th class science curiosity/by k sandeep s...
Sandeep Swamy
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
Arihant Class 10 All in One Maths full pdf
sajal kumar
 

09.1. Android - Local Database (Sqlite)

  • 1. 09.1. Database Oum Saokosal Master of Engineering in Information Systems, South Korea 855-12-252-752 [email protected]
  • 2. SQLite • SQLite is popular light-weight database • For Android, SQLite is "baked into" the Android runtime, so every Android application can create SQLite databases.
  • 3. Fundamental of SQL • Create a table: CREATE TABLE IF NOT EXISTS tbl_student ( stu_id INTEGER PRIMARY KEY AUTOINCREMENT, stu_name VARCHAR(50) NULL, stu_add VARCHAR(100) NULL, stu_gpa FLOAT NULL );
  • 4. • Insert a record: INSERT INTO tbl_student VALUES ( 80123, 'Sok Visal', 'Phnom Penh', 4.0 );
  • 5. • Select a record: SELECT * FROM tbl_student WHERE stu_id=80123 ORDER BY stu_name ASC • View many records: SELECT * FROM tbl_student WHERE stu_name LIKE '%sok%' ORDER BY stu_name DESC
  • 6. • Update a record: UPDATE tbl_student SET stu_name='Sok Visal', stu_add='Takeo', stu_gpa=4.0 WHERE stu_id = 80123;
  • 7. • Delete a record: DELETE FROM tbl_student WHERE stu_id=80123;
  • 8. SQLite Statements • To Create a database: SQLiteDatabase db = openOrCreateDatabase( "database_name", MODE_PRIVATE, null); • To execute a raw SQL statement: db.execSQL("CREATE TABLE tbl_product (pro_id integer, pro_name nvarchar(50));"); • To close a database: db.close();
  • 9. • To create a table by executing a raw SQL statement: db.execSQL("CREATE TABLE IF NOT EXISTS tbl_student (stu_id INT PRIMARY KEY AUTOINCREMENT, stu_name VARCHAR(50) NULL, stu_add VARCHAR(100) NULL, stu_gpa FLOAT);");
  • 10. • Insert a record: db.execSQL("INSERT INTO tbl_student VALUES (80123, 'Sok Visal', 'Phnom Penh', 4.0);");
  • 11. • Update a record: db.execSQL("UPDATE tbl_student SET stu_name='Sok Visal', stu_add='Takeo', stu_gpa=4.0 WHERE stu_id = 80123;");
  • 12. • Delete a record: db.execSQL("DELETE FROM tbl_student WHERE stu_id= 80123;");
  • 13. Records Retrieval • After you select records using SELECT, you need to display it. In Android, you will use Cursor class to store the records. Cursor result = db.rawQuery("SELECT * FROM tbl_student WHERE stu_id=80123 ORDER BY stu_name ASC", null);
  • 14. • Complete code of records retrieval: Cursor result = db.rawQuery("SELECT * FROM tbl_student WHERE stu_id=80123 ORDER BY stu_name ASC", null); result.moveToFirst(); //Must include this while(result.isAfterLast() != true){ int id = result.getInt(0); String name = result.getString(1); String address = result.getString(2); int gpa = result.getFloat(3); //Do something here result.moveToNext(); }
  • 15. Where is My Database? • Please note that to see the database folder, you need to run the emulator first. • After created a database, you can find it by going to DDMS -> File Explorer -> Then open the folder: data/data/your.app.package/databases/yourdbname
  • 17. How to View My Database? • There is a plugin that allows you to view SQLite file in Eclipse. Below is the url: http://www.tylerfrankenstein.com/user/4/browse-android- emulator-sqlite-database-eclipse • After you download it onto your machine, place it here:
  • 18. How to View My Database? Cont.
  • 19. Project Assignment • Think of your own favorite project related to a database and intent. And then make it a nice App for Android.
  • 20. Go on to the next slide