Best Android SQLite Database Select query Example

0
309

Introduction

Android SQLite database many people know about that. Before we implement a real query. I will start with the introduction. Android SQLite is the most preferred way to store data for android application.

I will share a complete tutorial android SQLite database which inserts and select data from a database in a really easy way. It is a very quick and easy way to connect store data in the database.

Prerequisite

“It will good to cover my previous articles before this. It helps to learn more about Android development. In which I explained.”

Android SQLite Database

Android SQLite open-source relation database is used to perform some common manipulating task. Android SQLite gives some method to performed create update delete SQL Commands. Here we are showing an example to insert and select data from the database.

In this post, I will show how to work with android SQLite. The SQL is a language to manipulate data in a relational database like SQL Server and Oracle.

  • SQLite is a scaled-down version of MySQL PostgreSQL and popular database systems.
  • Each application has its own SQLite.
  • The Database is accessible by any class in ap.
  • Transactional self-contained services less and use standard SQL language for executing queries.
  • Always create programmatically database for an app.

SQLiteOpenHelper class

This class take care of opening the database if it exists. Creating it if does not upgrade it as necessary. The SQLiteOpenHelper class consists of two main method of onCreate() and onUpgrade() methods of SQLiteOpenHelper class.

  • The onCreate() is called first when the database is created for the first time. The creation of data and table put here.
  • The upgrade() methods when the database needs to be upgraded using this method to add a table drop a table.

Step to create a database

  • Step 1 defines the database name table name and column name.
  • Step 2 create a database write a query to create modify a database.
  • Step 3 performed the insert select operation.

SQLiteDatabase class

This class has a method to perform create delete update SQL commands and also performed other command database management tasks.

  • For each application, the database must be unique with the application.
  • Execute a single SQL statement that is not a select or any other SQL statement that returns data.
  • Multiple statements separated by a semicolon is not supported.
  • if the SQL string is invalid throw an SQLExcepttion
Create a new Layout
->Right click> the ->layout folder-> select ->New option->and ->click ><-layout resource folder-> and<-After the layout is created>
<Paste the following code>

File:activity_main.xml

Create a new Class   

  • Create new class ->Right click-> the ->package name ->select ->New option-> and click-> java class <-Create new class ->
  • <Paste the following code on an activity that hosts the layout>
  • FirstActivity name is File: ( MainActivity.java)

Create a new Class

  • Create new class ->Right click-> the ->package name ->select ->New option-> and click-> java class <-Create new class ->
  • <Paste the following code on an activity that host the layout>
  • SecondActivity name is File: ( Second.java)

Create a new Class

  • Create new class ->Right click-> the ->package name ->select ->New option-> and click-> java class <-Create new class ->
  • <Paste the following code on an activity that host the layout>
  • ThirdActivity name is File: ( WelcomMessage.java)

Wrap UP

Here I completed an example of Android SQLite Database. My first task is to create a database schema. Here we define the column and rows according to our requirement. Two class defines also explained there method description.

Here is my example Simply we write the user name and password and click on the add button. Your data is stored and toast message is shown when I click on view button all the save data are shown.

I hope you got the idea. You will also Android SQLite database schema as your desire. if you like this please share it for more about it.

Previous articleHow to Validate The Keyword SEO|Drive Traffic
My name is Muhammad Zubair. I want to help you a lot of things that a blog provide. You feel free to ask the question anytime you might have! While most recently, he tends to share her wealth of knowledge and expertise on SEO, link building, inbound marketing,