0% found this document useful (0 votes)
13 views

Android & SQLite

SQLite is an open-source relational database integrated into Android for local data storage, allowing users to perform CRUD operations without needing a separate connection. Data is organized in tables similar to spreadsheets, and the SQLiteOpenHelper class facilitates database creation and management. Key methods in the SQLiteDatabase class include execSQL for executing queries, insert for adding records, and update for modifying existing data.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Android & SQLite

SQLite is an open-source relational database integrated into Android for local data storage, allowing users to perform CRUD operations without needing a separate connection. Data is organized in tables similar to spreadsheets, and the SQLiteOpenHelper class facilitates database creation and management. Key methods in the SQLiteDatabase class include execSQL for executing queries, insert for adding records, and update for modifying existing data.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Android

&
SQLite
SQLite
SQLite is another data storage
available in Android where we can store
data in the user’s device and can use it any
time when required. In this article, we will
take a look at creating an SQLite database
in the Android app and adding data to that
database in the Android app. It’s Common
Practice to Proform basic CRUD (Create,
Read, Update, and Delete) operation with
What is SQLite Database?
SQLite Database is an open-
source database provided in Android which is
used to store data inside the user’s device in the
form of a Text file. We can perform so many
operations on this data such as adding new data,
updating, reading, and deleting this data. SQLite
is an offline database that is locally stored in the
user’s device and we do not have to create any
connection to connect to this database.
Android SQLite Connection
• SQLite is an open-source relational database i.e.
used to perform database operations on android
devices such as storing, manipulating or
retrieving persistent data from the database.
• It is embedded in android bydefault. So, there is
no need to perform any database setup or
administration task.
• SQLiteOpenHelper class provides the functionality
to use the SQLite database.
How Data is Being Stored in the
SQLite Database?
Data is stored in the SQLite
database in the form of tables. When
we stored this data in our SQLite
database it is arranged in the form of
tables that are similar to that of an
excel sheet. Below is the representation
of our SQLite database which we are
storing in our SQLite database.
Important Methods in SQLite Database
Below are the several important methods that we will
be using in this SQLite database integration in Android.
Method Description
This method is used to get the Array of column
getColumnNames()
names of our SQLite table.
This method will return the number of rows in the
getCount()
cursor.
This method returns a Boolean value when our cursor
isClosed()
is closed.
This method returns the total number of columns
getColumnCount()
present in our table.
getColumnName(int This method will return the name of the column when
columnIndex) we passed the index of our column in it.
getColumnIndex(String This method will return the index of our column from
columnName) the name of the column.
This method will return the current position of our
getPosition()
cursor in our table.
SQLiteOpenHelper class
The android.database.sqlite.SQLiteOpenHelper
class is used for database creation and version
management. For performing any database operation, you
have to provide the implementation of onCreate() and
onUpgrade() methods of SQLiteOpenHelper class.
Constructors of SQLiteOpenHelper class
There are two constructors of SQLiteOpenHelper
class.
Constructor Description
SQLiteOpenHelper(Context context, String creates an object for creating, opening and
name, SQLiteDatabase.CursorFactory managing the database.
factory, int version)
SQLiteOpenHelper(Context context, String creates an object for creating, opening and
name, SQLiteDatabase.CursorFactory managing the database. It specifies the error
factory, int version, DatabaseErrorHandler handler.
SQLiteDatabase class
It contains methods to be performed on sqlite database such as
create, update, delete, select etc.
Methods of SQLiteDatabase class
There are many methods in SQLiteDatabase class. Some of them are as
follows
Method Description
void execSQL(String sql) executes the sql query not select query.
long insert(String table, String inserts a record on the database. The table
nullColumnHack, ContentValues values) specifies the table name, nullColumnHack
doesn't allow completely null values. If second
argument is null, android will store null values
if values are empty. The third argument
specifies the values to be stored.
int update(String table, ContentValues updates a row.
values, String whereClause, String[]
whereArgs)
Cursor query(String table, String[] returns a cursor over the resultset.
columns, String selection, String[]

You might also like