Prerequisite

If you not understand this lecture .how can add data into SQLite Database in android.You should also read my previous lectures Option Menu in android studio and Contextual Action mode in android studio . After reading these lecture you will also able to create Database of your Application.

Overview

Most of Application have to need to store small amount of data.And use Database is essential aspect of most of application. In android they are several ways to store data.While working with android studio you can store data in shared preference, file, and database.Android provide its own database name like SQLite. Most of all android device provide its own database name like SqlLite.

What is SQLite

SQLite is a embedded (RDBMS) Stand for Relation DataBase Management system.Most relation database such as ORACAL and SQL are example that are working independently and store the information.SQLite is referred to as embedded because it is provided in the form of a library that is linked into applications.The code for SQLite is in the public domain and is thus free for use for any purpose, commercial or private.There is no sever that are running in the background.All the Database function are perform internally.

Introduction

In this lecture well we describe how can create Database in android studio.And also describe what is SQLite.why we can use it.After Reading this lecture you will understand how can create a Database in android And i hope you will create Database of your application.

Description of Insert data into Database

In this lecture will describe how can working with Database in android studio.So we create a simple application that will describe how to create a database and add information into database.First of all we create project in android studio.Every project contain two file first is java class file and second is layout XML file.And we open a layout.XML file and add a button when user click on a button open a new activity.In that activity we will create three Edit text and one button.when user click on button data saved into database.So this is a work that will done this section.please read this lecture carefully all the detail is provides step by step.

Layout XML BASIC

XML Layout 

First of you will open a XML file of layout and set Linear Layout  and add  Edit text

Different property that are used in layout.xml file  explain here

  • warp_content   warp_content means height and width similar to the text that are entered.
  • Match_parent   means height and width similar to parent.
  • Edit text              The Edit Text control allows a user to enter text into an application
  • Button                  When user click on a button store information into database and show message

 And Write the following code in Activity_main.XML file

Now we create a new Layout.

  • <- create a new Layout< Nameadddata_layout->Right click> the ->layout folder-> select ->New option-> and click ->layout resource folder->
  • WriteName->Ok.

In this example we are going to create a simple UI that includes only (Edit text) and (Button)with Different attributes  And Write the following code in adddata_layout .XML file:

Step1=Create new class <-NewContactActivity ->Right click-> the ->package name ->select ->New option-> and click-> java class that will show in below.  

Alt Tag Android make new class

Step2=Step1->WriteName->Ok

Alt Tag android sqlite new class

And Write the following code NewContactActivity. java class

  • Step3=Create new class <-UserContract ->Right click-> the ->package name ->select ->New option-> and click-> java class that will show in above. 
  •  Step4=Step3->WriteName->Ok
  • if you not understand this please read first step
  • And Write the following code UserContract. java class

  • Step5=Create new class <-UserDbHandler ->Right click-> the ->package name ->select ->New option-> and click-> java class that will show in above. 
  •  Step6=Step5->WriteName->Ok.
  • if you not understand this  please read step 1.
  • And Write the following code UserDbHandler. java class

And Write the following code MainACtivity. java class

Run the Application

This picture consists of three Edit text and a button .when user add information in edit text and click on save button then all the information will saved in database.

Alt Tag android sqlite out image

when you connected the database SQLite.This type of message will show

  • Database is create and open
  • Table is create
  • One row is insert in database

Alt Tag andrid datbase create

 Conclusion

In this lecture we learn about Android SqLite database.And also learn about use of database in application.we will leaen about connection of database and insert data into database and  also create table. I hope you will understand this lecture.Thank you for reading this lecture Hope you got the idea.

  • Ghani Khan

    i have an error cannot resolve symbol UserDbHelper