Android training easy steps to work with sqlite database for data management

Page 1

Android Training – Steps to Work with SQLite Database for Data Management SQLite is an open source database that provides a facility for storing and management of the user data in Android device. This is present in every device having Android OS and hence needs to be handled CRUD (Create, Read, Update & Delete) functionalities for data management. In this article, we are going to learn about the easy ways to create a table in the database, add and read data from it, upgrade the existing table data and finally delete the data. Now let us take an example of storing the trainee details in the database. For this here we are using the Class called Trainee to store the details. This table contains three columns – first is to store the ID of the trainee, second stores the name of the student and the last third column is used to store name of the course the trainee has joined. Field Trainee_ID Trainee_Name Course_Name

Type Int Text Text

Key Primary Key

Step 1: Defining the Trainee Class Now initially we will define the Trainee class using the get and set methods. For Example: Trainee.java package com.androidhive.androidsqlite; public class Trainee { //We declare the variables to be used in the class. These are the private variables. int _trainee_id; String _trainee_name; String _course_name; // Empty constructor to prevent someone from accidentally instantiating the trainee class public Trainee() { } // Constructor public Trainee(int trainee_id, String trainee_name, String course_name){ this._ trainee_id = trainee_id; this._ trainee_name = trainee_name; this._ course_name = course_name; } // Get & Set the Trainee ID


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.