SQlite. SQLite is a opensource SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation.

Slides:



Advertisements
Similar presentations
PHP II Interacting with Database Data. The whole idea of a database-driven website is to enable the content of the site to reside in a database, and to.
Advertisements

SQLite. Command line sqlite3 The command line sqlite3 is not installed on all devices To install, get sqlite3 from web page, and $ adb push sqlite3 /sdcard/
CE881: Mobile and Social Application Programming Flexible Data Handling with Integrity: SQLite Simon M. Lucas.
SQLite is a software library. It is: self-contained + Serverless + zero-configuration transactional = SQL database engine. Most widely deployed. The source.
SQLite in Mobile Apps by Dan Youberg. Overview Many well known applications and Internet browsers use SQLite due to its very small size (~250 Kb). Also.
Manipulating MySQL Databases with PHP. PHP and mySQL2 Objectives Connect to MySQL from PHP Learn how to handle MySQL errors Execute SQL statements with.
A Guide to SQL, Seventh Edition. Objectives Embed SQL commands in PL/SQL programs Retrieve single rows using embedded SQL Update a table using embedded.
CONTENT PROVIDER. Content Provider  A content provider makes a specific set of the application's data available to other applications => Share data to.
Cosc 5/4730 Android and Blackberry SQLite. For the sql language syntax, please see SQlite documentation –
SQLLite and Java CS-328 Dick Steflik. SQLLite Embedded RDBMS ACID Compliant Size – about 257 Kbytes Not a client/server architecture –Accessed via function.
Data Persistence in Android
SQLite Database. SQLite Public domain database – Advantages Small (about 150 KB) – Used on devices with limited resources Each database contained within.
Database Rung-Hung Gau Department of Computer Science and Engineering
PHP1-1 PHP & SQL Xingquan (Hill) Zhu
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
Chapter 7 PHP Interacts with Ms. Access (Open DataBase Connectivity (ODBC))
Beginning Databases with JDBC Mike Bradley Adapted from and notes by Kevin Parker, Ph.D.
Java Utility Classes CS 21b. Some Java Utility Classes Vector Hashtable StringTokenizer * import java.util.*;
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Data Storage: Part 4 (Content Providers). Content Providers Content providers allow the sharing of data between applications. Inter-process communication.
COMP 365 Android Development.  Manages access from a central database  Allows multiple applications to access the same data.
Python MySQL Database Access
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 38 Advanced Java Database.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
SQLite Android Club SQLite About onCreate Insert Select Update Delete onUpdate.
JDBC. JDBC stands for Java Data Base Connectivity. JDBC is different from ODBC in that – JDBC is written in Java (hence is platform independent, object.
Advanced SQL: Cursors & Stored Procedures
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 33 Advanced Java.
Stored Procedures Week 9. Test Details Stored Procedures SQL can call code written in iSeries High Level Languages –Called stored procedures SQL has.
Course FAQ’s I do not have any knowledge on SQL concepts or Database Testing. Will this course helps me to get through all the concepts? What kind of.
JDBC. Java.sql.package The java.sql package contains various interfaces and classes used by the JDBC API. This collection of interfaces and classes enable.
Mauricio Featherman, Ph.D. Washington St. University
SQLite (part deux) 1 CS440. Traditional Model View Controller (MVC) CS440 2.
Mobile Software Development ISCG 7424 Department of Computing UNITEC John Casey and Richard Rabeder SQLite and Permissions.
JDBC CS 124. JDBC Java Database Connectivity Database Access Interface provides access to a relational database (by allowing SQL statements to be sent.
Li Tak Sing COMPS311F. Database programming JDBC (Java Database Connectivity) Java version of ODBC (Open Database Connectivity) ODBC provides a standard.
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
SQLite DB Storing Data in Android RAVI GAURAV PANDEY 1.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
Android - SQLite Database 12/10/2015. Introduction SQLite is a opensource SQL database that stores data to a text file on a device. Android comes in with.
Android Storage MAY 2013 Hu.Cai. NAME OF PRESENTATION [CHANGE IN SLIDE MASTER] MONTH, YEAR [CHANGE IN SLIDE MASTER] Outline 1.Storage In General 2.SharedPreferences.
By: Eliav Menachi.  On Android, all application data (including files) are private to that application  Android provides a standard way for an application.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Data Storage in Android Димитър Н. Димитров. Why talk about data? Why not 3D graphics or network connectivity? Data as fundamental term in computer science.
Making content providers
Data Storage: Part 3 (SQLite)
Chapter 38 Advanced Java Database Programming
Cosc 5/4730 Sqlite primer.
Android Content Providers & SQLite
Mobile Applications (Android Programming)
SQLite in Android Landon Cox March 2, 2017.
A Guide to SQL, Seventh Edition
Mobile Application Development BSCS-7 Lecture # 18, 19
Mobile Applications (Android Programming)
Reactive Android Development
Chapter 41 Advanced Java Database Programming
Android Database using SQLite
Mobile Computing With Android ACST Android Database Storage Part 2
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
CMPE419 Mobile Application Development
CMPE419 Mobile Application Development
Mobile Computing With Android ACST 4550 Android Database Storage
Android Developer Fundamentals V2
JDBC Example.
ListView A view that shows items in a vertically scrolling list. The items come from the ListAdapter associated with this view. ListAdapter is used to.
Department of School of Computing and Engineering
SQLLite and Android.
Mobile Programming Dr. Mohsin Ali Memon.
Presentation transcript:

SQlite

SQLite is a opensource SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation. SQLite supports all the relational database features. In order to access this database, you don't need to establish any kind of connections for it like JDBC,ODBC e.t.c

The main package is android.database.sqlite that contains the classes to manage your own databases. To create a database you just need to call this method openOrCreateDatabase with your database name and mode as a parameter. It returns an instance of SQLite database which you have to receive in your own object. Example SQLiteDatabase mydatabase = openOrCreateDatabase("your database name",MODE_PRIVATE,null);

The various methods are openDatabase(String path, SQLiteDatabase.CursorFactory factory, int flags, DatabaseErrorHandler errorHandler)This method only opens the existing database with the appropriate flag mode. The common flags mode could be OPEN_READWRITE OPEN_READONLY openDatabase(String path, SQLiteDatabase.CursorFactory factory, int flags)It is similar to the above method as it also opens the existing database but it does not define any handler to handle the errors of databases openOrCreateDatabase(String path, SQLiteDatabase.CursorFactory factory)It not only opens but create the database if it not exists. This method is equivalent to openDatabase method

openOrCreateDatabase(File file, SQLiteDatabase.CursorFactory factory)This method is similar to above method but it takes the File object as a path rather then a string. It is equivalent to file.getPath()

Insert data we can create table or insert data into table using execSQL method defined in SQLiteDatabase class. mydatabase.execSQL("CREATE TABLE IF NOT EXISTS MyTable(Username VARCHAR,Password VARCHAR);"); mydatabase.execSQL("INSERT INTO MyTable VALUES('admin','admin');");

Another way execSQL(String sql, Object[] bindArgs)This method not only insert data, but also used to update or modify already existing data in database using bind arguments.

Fetching data from database We can retrieve anything from database using an object of the Cursor class. We will call a method of this class called rawQuery and it will return a result set with the cursor pointing to the table. We can move the cursor forward and retrieve the data.

Cursor resultSet = mydatabase.rawQuery("Select * from MyTable ",null); resultSet.moveToFirst(); String username = resultSet.getString(1); String password = resultSet.getString(2);

There are other functions available in the Cursor class that allows us to effectively retrieve the data. getColumnCount()This method return the total number of columns of the table. getColumnIndex(String columnName)This method returns the index number of a column by specifying the name of the column getColumnName(int columnIndex)This method returns the name of the column by specifying the index of the column getColumnNames()This method returns the array of all the column names of the table. getCount()This method returns the total number of rows in the cursor

getPosition()This method returns the current position of the cursor in the table isClosed()This method returns true if the cursor is closed and return false otherwise

Helper class For managing all the operations related to the database, an helper class has been given and is called SQLiteOpenHelper. It automatically manages the creation and update of the database.

public class DBHelper extends SQLiteOpenHelper { public DBHelper(){ super(context,DATABASE_NAME,null,1); } public void onCreate(SQLiteDatabase db) {} public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {} }

The full code of the onCreate() method of the main activity.

The db.execSQL() function to insert a student record in the student table.

The DELETE command can be executed as follows:

The UPDATE command can be executed as follows:

To view a student record, we execute a query using the rawQuery() method of the SQLiteDatabase class as follows:

To view all records, the following code can be used: