SlideShare a Scribd company logo
SAVE DATA INTO
SQLITE
Android Studio – Case sample in “create user table”
Map Directory
• OpenHelper : used for helper database
• DbUser : class user that data will be save in SQLite DB
• StartUpActivity : class that will be sample to
implement save and read user data
OpenHelper Class
package com.trans.junifar.transpot.db.sqlite;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
/**
* Created by junifar on 06-Jun-16.
*/
public class OpenHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "MyDB.db";
private static final int DATABASE_VERSION = 1;
private static final String TABLE_CREATE = "CREATE TABLE USER" +
"(" +
"ID INTEGER PRIMARY KEY AUTOINCREMENT," +
"NAME TEXT," +
"PHONE TEXT" +
")";
public OpenHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(TABLE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXIST USER");
}
}
DbUser Class
package com.trans.junifar.transpot.db.sqlite;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
/**
* Created by junifar on 06-Jun-16.
*/
public class DbUser {
private final OpenHelper dbHelper;
public static class User {
public String name;
public String phone;
}
private SQLiteDatabase db;
public DbUser(Context c){
dbHelper = new OpenHelper(c);
}
public void open(){
db = dbHelper.getWritableDatabase();
}
public void close(){
db.close();
}
public long insertUser(
String name,
String phone
){
ContentValues newValues = new ContentValues();
newValues.put("name",name);
newValues.put("phone",phone);
return db.insert("USER",null,newValues);
}
public User getUser(String name){
Cursor cur = null;
User usr = new User();
String[] cols = new String[]{"ID","NAME","PHONE"};
String[] param = {name};
cur = db.query("USER",cols,"NAME=?",param,null,null,null);
if (cur.getCount() > 0){
cur.moveToFirst();
usr.name = cur.getString(1);
usr.phone = cur.getString(2);
}
return usr;
}
}
StartUpActivity (OnCreate)
public class StartUpActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start_up);
DbUser db = new DbUser(getApplicationContext());
db.open();
db.insertUser("Junifar Hidayat","08567988422");
DbUser.User user = db.getUser("Junifar Hidayat");
AlertDialog ad = new AlertDialog.Builder(this).create();
ad.setMessage("Nama : "+user.name+" Phone : "+user.phone);
ad.show();
}
}
THAT’S ALL
Thank you
External Reference
• http://indonesiaberkicau.com/menyimpan-data-di-database-sql/

More Related Content

What's hot

07.3. Android Alert message, List, Dropdown, and Auto Complete
07.3. Android Alert message, List, Dropdown, and Auto Complete07.3. Android Alert message, List, Dropdown, and Auto Complete
07.3. Android Alert message, List, Dropdown, and Auto Complete
Oum Saokosal
 
Data Management in Microsoft HDInsight: How to Move and Store Your Data
Data Management in Microsoft HDInsight: How to Move and Store Your DataData Management in Microsoft HDInsight: How to Move and Store Your Data
Data Management in Microsoft HDInsight: How to Move and Store Your Data
Saptak Sen
 
Drupal node access system & AUL 7.x.-2.x
Drupal node access system & AUL 7.x.-2.xDrupal node access system & AUL 7.x.-2.x
Drupal node access system & AUL 7.x.-2.x
Oleksandr Milkovskyi
 
MobileCity:Core Data
MobileCity:Core DataMobileCity:Core Data
MobileCity:Core Data
Allan Davis
 
Inicializacao win7
Inicializacao win7Inicializacao win7
Inicializacao win7
Yury Macedo Correia
 
Tutorial MySQL com Java
Tutorial MySQL com JavaTutorial MySQL com Java
Tutorial MySQL com Java
MySQL Brasil
 
Synapseindia android middleware
Synapseindia android middlewareSynapseindia android middleware
Synapseindia android middleware
Synapseindiappsdevelopment
 
Plsql
PlsqlPlsql
Azure 2
Azure 2Azure 2
Azure 2
Eren Caner
 
Php5
Php5Php5
Backups with Exported Resources - Zach Leslie, Puppet Labs
Backups with Exported Resources - Zach Leslie, Puppet Labs Backups with Exported Resources - Zach Leslie, Puppet Labs
Backups with Exported Resources - Zach Leslie, Puppet Labs
Puppet
 

What's hot (11)

07.3. Android Alert message, List, Dropdown, and Auto Complete
07.3. Android Alert message, List, Dropdown, and Auto Complete07.3. Android Alert message, List, Dropdown, and Auto Complete
07.3. Android Alert message, List, Dropdown, and Auto Complete
 
Data Management in Microsoft HDInsight: How to Move and Store Your Data
Data Management in Microsoft HDInsight: How to Move and Store Your DataData Management in Microsoft HDInsight: How to Move and Store Your Data
Data Management in Microsoft HDInsight: How to Move and Store Your Data
 
Drupal node access system & AUL 7.x.-2.x
Drupal node access system & AUL 7.x.-2.xDrupal node access system & AUL 7.x.-2.x
Drupal node access system & AUL 7.x.-2.x
 
MobileCity:Core Data
MobileCity:Core DataMobileCity:Core Data
MobileCity:Core Data
 
Inicializacao win7
Inicializacao win7Inicializacao win7
Inicializacao win7
 
Tutorial MySQL com Java
Tutorial MySQL com JavaTutorial MySQL com Java
Tutorial MySQL com Java
 
Synapseindia android middleware
Synapseindia android middlewareSynapseindia android middleware
Synapseindia android middleware
 
Plsql
PlsqlPlsql
Plsql
 
Azure 2
Azure 2Azure 2
Azure 2
 
Php5
Php5Php5
Php5
 
Backups with Exported Resources - Zach Leslie, Puppet Labs
Backups with Exported Resources - Zach Leslie, Puppet Labs Backups with Exported Resources - Zach Leslie, Puppet Labs
Backups with Exported Resources - Zach Leslie, Puppet Labs
 

Viewers also liked

Brosur tulisan
Brosur tulisanBrosur tulisan
Brosur tulisan
Jasa Service Hp Sidoarjo
 
Tolerance and grit
Tolerance and gritTolerance and grit
Tolerance and grit
Paul Yang
 
Presentación handball4ºeso
Presentación handball4ºesoPresentación handball4ºeso
Presentación handball4ºeso
gonzalo Peña
 
Loadแนวข้อสอบ พนักงานวางผังเมือง (ปริญญาตรี) กรมโยธาธิการและผังเมือง
Loadแนวข้อสอบ พนักงานวางผังเมือง (ปริญญาตรี) กรมโยธาธิการและผังเมืองLoadแนวข้อสอบ พนักงานวางผังเมือง (ปริญญาตรี) กรมโยธาธิการและผังเมือง
Loadแนวข้อสอบ พนักงานวางผังเมือง (ปริญญาตรี) กรมโยธาธิการและผังเมือง
nawaporn khamseanwong
 
My cv1.pdf
My cv1.pdfMy cv1.pdf
My cv1.pdf
Mahmoud Anwar
 
Revista digital
Revista digitalRevista digital
Revista digital
Yerling Torres Vega
 
Producción y Desarrollo Sustentable
Producción y Desarrollo SustentableProducción y Desarrollo Sustentable
Producción y Desarrollo Sustentable
JosephApPa
 
σπίτια
σπίτιασπίτια
영화속 와인 이야기
영화속 와인 이야기영화속 와인 이야기
영화속 와인 이야기
휘웅 정
 
000024
000024000024
000024
utyyflbq
 
презентация Microsoft office power point 2007
презентация Microsoft office power point 2007презентация Microsoft office power point 2007
презентация Microsoft office power point 2007
utyyflbq
 
Digitális történetmesélés és kiterjesztett valóság – újszerű lehetőségek az i...
Digitális történetmesélés és kiterjesztett valóság – újszerű lehetőségek az i...Digitális történetmesélés és kiterjesztett valóság – újszerű lehetőségek az i...
Digitális történetmesélés és kiterjesztett valóság – újszerű lehetőségek az i...
Balázs Czékmán
 
Conflict: A Fairy Tail - Victoria Smith
Conflict: A Fairy Tail - Victoria SmithConflict: A Fairy Tail - Victoria Smith
Conflict: A Fairy Tail - Victoria Smith
Mary-Katherine Kearney
 
AGRICULTURE PRICING POLICY
AGRICULTURE PRICING POLICYAGRICULTURE PRICING POLICY
AGRICULTURE PRICING POLICY
Nisha Munshi
 
Social dance
Social danceSocial dance
Social dance
Al-lyn Vocal
 
EdTech & New Media
EdTech & New Media EdTech & New Media
EdTech & New Media
Sascha Funk
 
If job boards died - where would you get your candidates?
If job boards died - where would you get your candidates?If job boards died - where would you get your candidates?
If job boards died - where would you get your candidates?
Jobs2web
 
IVI Training Implementing The Venture Loan Model In Canada
IVI Training Implementing The Venture Loan Model In CanadaIVI Training Implementing The Venture Loan Model In Canada
IVI Training Implementing The Venture Loan Model In Canada
Thomas Nastas
 
Best Practices on Recruiting Participants for Remote User Testing
Best Practices on Recruiting Participants for Remote User TestingBest Practices on Recruiting Participants for Remote User Testing
Best Practices on Recruiting Participants for Remote User Testing
UserZoom
 
Play The Game
Play The GamePlay The Game

Viewers also liked (20)

Brosur tulisan
Brosur tulisanBrosur tulisan
Brosur tulisan
 
Tolerance and grit
Tolerance and gritTolerance and grit
Tolerance and grit
 
Presentación handball4ºeso
Presentación handball4ºesoPresentación handball4ºeso
Presentación handball4ºeso
 
Loadแนวข้อสอบ พนักงานวางผังเมือง (ปริญญาตรี) กรมโยธาธิการและผังเมือง
Loadแนวข้อสอบ พนักงานวางผังเมือง (ปริญญาตรี) กรมโยธาธิการและผังเมืองLoadแนวข้อสอบ พนักงานวางผังเมือง (ปริญญาตรี) กรมโยธาธิการและผังเมือง
Loadแนวข้อสอบ พนักงานวางผังเมือง (ปริญญาตรี) กรมโยธาธิการและผังเมือง
 
My cv1.pdf
My cv1.pdfMy cv1.pdf
My cv1.pdf
 
Revista digital
Revista digitalRevista digital
Revista digital
 
Producción y Desarrollo Sustentable
Producción y Desarrollo SustentableProducción y Desarrollo Sustentable
Producción y Desarrollo Sustentable
 
σπίτια
σπίτιασπίτια
σπίτια
 
영화속 와인 이야기
영화속 와인 이야기영화속 와인 이야기
영화속 와인 이야기
 
000024
000024000024
000024
 
презентация Microsoft office power point 2007
презентация Microsoft office power point 2007презентация Microsoft office power point 2007
презентация Microsoft office power point 2007
 
Digitális történetmesélés és kiterjesztett valóság – újszerű lehetőségek az i...
Digitális történetmesélés és kiterjesztett valóság – újszerű lehetőségek az i...Digitális történetmesélés és kiterjesztett valóság – újszerű lehetőségek az i...
Digitális történetmesélés és kiterjesztett valóság – újszerű lehetőségek az i...
 
Conflict: A Fairy Tail - Victoria Smith
Conflict: A Fairy Tail - Victoria SmithConflict: A Fairy Tail - Victoria Smith
Conflict: A Fairy Tail - Victoria Smith
 
AGRICULTURE PRICING POLICY
AGRICULTURE PRICING POLICYAGRICULTURE PRICING POLICY
AGRICULTURE PRICING POLICY
 
Social dance
Social danceSocial dance
Social dance
 
EdTech & New Media
EdTech & New Media EdTech & New Media
EdTech & New Media
 
If job boards died - where would you get your candidates?
If job boards died - where would you get your candidates?If job boards died - where would you get your candidates?
If job boards died - where would you get your candidates?
 
IVI Training Implementing The Venture Loan Model In Canada
IVI Training Implementing The Venture Loan Model In CanadaIVI Training Implementing The Venture Loan Model In Canada
IVI Training Implementing The Venture Loan Model In Canada
 
Best Practices on Recruiting Participants for Remote User Testing
Best Practices on Recruiting Participants for Remote User TestingBest Practices on Recruiting Participants for Remote User Testing
Best Practices on Recruiting Participants for Remote User Testing
 
Play The Game
Play The GamePlay The Game
Play The Game
 

Similar to Save data in to sqlite

Database in Android
Database in AndroidDatabase in Android
Database in Android
MaryadelMar85
 
Android Architecture Components - Guy Bar on, Vonage
Android Architecture Components - Guy Bar on, VonageAndroid Architecture Components - Guy Bar on, Vonage
Android Architecture Components - Guy Bar on, Vonage
DroidConTLV
 
F1
F1F1
9 content-providers
9 content-providers9 content-providers
9 content-providers
Aravindharamanan S
 
Databases in Android Application
Databases in Android ApplicationDatabases in Android Application
Databases in Android Application
Mark Lester Navarro
 
A evolução da persistência de dados (com sqlite) no android
A evolução da persistência de dados (com sqlite) no androidA evolução da persistência de dados (com sqlite) no android
A evolução da persistência de dados (com sqlite) no android
Rodrigo de Souza Castro
 
Android-data storage in android-chapter21
Android-data storage in android-chapter21Android-data storage in android-chapter21
Android-data storage in android-chapter21
Dr. Ramkumar Lakshminarayanan
 
Using database in android
Using database in androidUsing database in android
Using database in android
University of Potsdam
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android
Aakash Ugale
 
Android Data Persistence
Android Data PersistenceAndroid Data Persistence
Android Data Persistence
Romain Rochegude
 
Architecture components - IT Talk
Architecture components - IT TalkArchitecture components - IT Talk
Architecture components - IT Talk
Constantine Mars
 
Architecture Components
Architecture Components Architecture Components
Architecture Components
DataArt
 
Everything about storage - DroidconMtl 2015
Everything about storage - DroidconMtl 2015Everything about storage - DroidconMtl 2015
Everything about storage - DroidconMtl 2015
Cindy Potvin
 
Android App Development - 09 Storage
Android App Development - 09 StorageAndroid App Development - 09 Storage
Android App Development - 09 Storage
Diego Grancini
 
Android Database Tutorial
Android Database TutorialAndroid Database Tutorial
Android Database Tutorial
Perfect APK
 
Android sql examples
Android sql examplesAndroid sql examples
Android sql examples
Aravindharamanan S
 
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
 
12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptx12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptx
FaezNasir
 
Android App Development 05 : Saving Data
Android App Development 05 : Saving DataAndroid App Development 05 : Saving Data
Android App Development 05 : Saving Data
Anuchit Chalothorn
 
Android Data Storagefinal
Android Data StoragefinalAndroid Data Storagefinal
Android Data Storagefinal
Nakka Srilakshmi
 

Similar to Save data in to sqlite (20)

Database in Android
Database in AndroidDatabase in Android
Database in Android
 
Android Architecture Components - Guy Bar on, Vonage
Android Architecture Components - Guy Bar on, VonageAndroid Architecture Components - Guy Bar on, Vonage
Android Architecture Components - Guy Bar on, Vonage
 
F1
F1F1
F1
 
9 content-providers
9 content-providers9 content-providers
9 content-providers
 
Databases in Android Application
Databases in Android ApplicationDatabases in Android Application
Databases in Android Application
 
A evolução da persistência de dados (com sqlite) no android
A evolução da persistência de dados (com sqlite) no androidA evolução da persistência de dados (com sqlite) no android
A evolução da persistência de dados (com sqlite) no android
 
Android-data storage in android-chapter21
Android-data storage in android-chapter21Android-data storage in android-chapter21
Android-data storage in android-chapter21
 
Using database in android
Using database in androidUsing database in android
Using database in android
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android
 
Android Data Persistence
Android Data PersistenceAndroid Data Persistence
Android Data Persistence
 
Architecture components - IT Talk
Architecture components - IT TalkArchitecture components - IT Talk
Architecture components - IT Talk
 
Architecture Components
Architecture Components Architecture Components
Architecture Components
 
Everything about storage - DroidconMtl 2015
Everything about storage - DroidconMtl 2015Everything about storage - DroidconMtl 2015
Everything about storage - DroidconMtl 2015
 
Android App Development - 09 Storage
Android App Development - 09 StorageAndroid App Development - 09 Storage
Android App Development - 09 Storage
 
Android Database Tutorial
Android Database TutorialAndroid Database Tutorial
Android Database Tutorial
 
Android sql examples
Android sql examplesAndroid sql examples
Android sql examples
 
ANDROID USING SQLITE DATABASE ADMINISTRATORS ~HMFTJ
ANDROID USING SQLITE DATABASE ADMINISTRATORS ~HMFTJANDROID USING SQLITE DATABASE ADMINISTRATORS ~HMFTJ
ANDROID USING SQLITE DATABASE ADMINISTRATORS ~HMFTJ
 
12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptx12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.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 Data Storagefinal
Android Data StoragefinalAndroid Data Storagefinal
Android Data Storagefinal
 

More from Junifar hidayat

Linux Swap
Linux SwapLinux Swap
Linux Swap
Junifar hidayat
 
Vlookup – microsoft excel
Vlookup – microsoft excelVlookup – microsoft excel
Vlookup – microsoft excel
Junifar hidayat
 
OpenERP Relation Account Invoice, Account Voucher, Account Move Line
OpenERP Relation Account Invoice, Account Voucher, Account Move LineOpenERP Relation Account Invoice, Account Voucher, Account Move Line
OpenERP Relation Account Invoice, Account Voucher, Account Move Line
Junifar hidayat
 
Firebase recycler adapter
Firebase recycler adapterFirebase recycler adapter
Firebase recycler adapter
Junifar hidayat
 
Android tab layout Simple Implementation
Android tab layout Simple ImplementationAndroid tab layout Simple Implementation
Android tab layout Simple Implementation
Junifar hidayat
 
Action button open erp
Action button open erpAction button open erp
Action button open erp
Junifar hidayat
 
Open erp 7 workflow
Open erp 7 workflowOpen erp 7 workflow
Open erp 7 workflow
Junifar hidayat
 
OpenERP - Call specific Form / Tree view from Menu
OpenERP - Call specific Form / Tree view from MenuOpenERP - Call specific Form / Tree view from Menu
OpenERP - Call specific Form / Tree view from Menu
Junifar hidayat
 
Membuat virtual environment python
Membuat virtual environment pythonMembuat virtual environment python
Membuat virtual environment python
Junifar hidayat
 
Panduan microsoft outlook pemula
Panduan microsoft outlook pemulaPanduan microsoft outlook pemula
Panduan microsoft outlook pemula
Junifar hidayat
 
Binding radgridview into reportviewer
Binding radgridview into reportviewerBinding radgridview into reportviewer
Binding radgridview into reportviewer
Junifar hidayat
 
[Winform] Visual studio C# 2012 Setting themes with telerik themes library
[Winform] Visual studio C# 2012 Setting themes with telerik themes library[Winform] Visual studio C# 2012 Setting themes with telerik themes library
[Winform] Visual studio C# 2012 Setting themes with telerik themes library
Junifar hidayat
 
[Winform] Visual studio C# 2012 upload ftp
[Winform] Visual studio C# 2012 upload ftp[Winform] Visual studio C# 2012 upload ftp
[Winform] Visual studio C# 2012 upload ftp
Junifar hidayat
 

More from Junifar hidayat (13)

Linux Swap
Linux SwapLinux Swap
Linux Swap
 
Vlookup – microsoft excel
Vlookup – microsoft excelVlookup – microsoft excel
Vlookup – microsoft excel
 
OpenERP Relation Account Invoice, Account Voucher, Account Move Line
OpenERP Relation Account Invoice, Account Voucher, Account Move LineOpenERP Relation Account Invoice, Account Voucher, Account Move Line
OpenERP Relation Account Invoice, Account Voucher, Account Move Line
 
Firebase recycler adapter
Firebase recycler adapterFirebase recycler adapter
Firebase recycler adapter
 
Android tab layout Simple Implementation
Android tab layout Simple ImplementationAndroid tab layout Simple Implementation
Android tab layout Simple Implementation
 
Action button open erp
Action button open erpAction button open erp
Action button open erp
 
Open erp 7 workflow
Open erp 7 workflowOpen erp 7 workflow
Open erp 7 workflow
 
OpenERP - Call specific Form / Tree view from Menu
OpenERP - Call specific Form / Tree view from MenuOpenERP - Call specific Form / Tree view from Menu
OpenERP - Call specific Form / Tree view from Menu
 
Membuat virtual environment python
Membuat virtual environment pythonMembuat virtual environment python
Membuat virtual environment python
 
Panduan microsoft outlook pemula
Panduan microsoft outlook pemulaPanduan microsoft outlook pemula
Panduan microsoft outlook pemula
 
Binding radgridview into reportviewer
Binding radgridview into reportviewerBinding radgridview into reportviewer
Binding radgridview into reportviewer
 
[Winform] Visual studio C# 2012 Setting themes with telerik themes library
[Winform] Visual studio C# 2012 Setting themes with telerik themes library[Winform] Visual studio C# 2012 Setting themes with telerik themes library
[Winform] Visual studio C# 2012 Setting themes with telerik themes library
 
[Winform] Visual studio C# 2012 upload ftp
[Winform] Visual studio C# 2012 upload ftp[Winform] Visual studio C# 2012 upload ftp
[Winform] Visual studio C# 2012 upload ftp
 

Recently uploaded

Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
lorraineandreiamcidl
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
kalichargn70th171
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 

Recently uploaded (20)

Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 

Save data in to sqlite

  • 1. SAVE DATA INTO SQLITE Android Studio – Case sample in “create user table”
  • 2. Map Directory • OpenHelper : used for helper database • DbUser : class user that data will be save in SQLite DB • StartUpActivity : class that will be sample to implement save and read user data
  • 3. OpenHelper Class package com.trans.junifar.transpot.db.sqlite; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; /** * Created by junifar on 06-Jun-16. */ public class OpenHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "MyDB.db"; private static final int DATABASE_VERSION = 1; private static final String TABLE_CREATE = "CREATE TABLE USER" + "(" + "ID INTEGER PRIMARY KEY AUTOINCREMENT," + "NAME TEXT," + "PHONE TEXT" + ")"; public OpenHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL(TABLE_CREATE); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXIST USER"); } }
  • 4. DbUser Class package com.trans.junifar.transpot.db.sqlite; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; /** * Created by junifar on 06-Jun-16. */ public class DbUser { private final OpenHelper dbHelper; public static class User { public String name; public String phone; } private SQLiteDatabase db; public DbUser(Context c){ dbHelper = new OpenHelper(c); } public void open(){ db = dbHelper.getWritableDatabase(); } public void close(){ db.close(); } public long insertUser( String name, String phone ){ ContentValues newValues = new ContentValues(); newValues.put("name",name); newValues.put("phone",phone); return db.insert("USER",null,newValues); } public User getUser(String name){ Cursor cur = null; User usr = new User(); String[] cols = new String[]{"ID","NAME","PHONE"}; String[] param = {name}; cur = db.query("USER",cols,"NAME=?",param,null,null,null); if (cur.getCount() > 0){ cur.moveToFirst(); usr.name = cur.getString(1); usr.phone = cur.getString(2); } return usr; } }
  • 5. StartUpActivity (OnCreate) public class StartUpActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_start_up); DbUser db = new DbUser(getApplicationContext()); db.open(); db.insertUser("Junifar Hidayat","08567988422"); DbUser.User user = db.getUser("Junifar Hidayat"); AlertDialog ad = new AlertDialog.Builder(this).create(); ad.setMessage("Nama : "+user.name+" Phone : "+user.phone); ad.show(); } }