Header Ads

Android Sqlite Database With Complete Implementation Part 1

In this Tutorial You will learn about Android sqlite database practicaly. How works Android and sqlite work to gather first. You need to know about sqlile database. Sqlite database is an open source database which provide relation data.It dn't need any server or hosting it localy placed in android devices. To create and upgrade the android sqlite database you will need to extends SqliteOpenHelper class from child class. In this way you can create and upgrade your database.

Source Code goes here.
activity_main.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context="com.example.saud.mysqliteapp.MainActivity">

    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Hello World!" />
</RelativeLayout>
________________________________________________________________________________________

MainActivity.java

package com.example.saud.mysqliteapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}
_________________________________________________________________________________________

DatabaseHelper.java

package com.example.saud.mysqliteapp;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/** * Created by Itmulc on 8/10/2016. */public class DatabaseHelper extends SQLiteOpenHelper {

    final static String Database_name="empDb.db";

    public DatabaseHelper(Context context) {
        super(context, Database_name, null, 1);
    }
    @Override    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table emp_tbl (id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT,salary TEXT)");
    }

    @Override    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS tbl_emp");
    }
}

Watch the video





Disqus Shortname

Comments system

Powered by Blogger.