Android SQLite Tutorial | Android CRUD Tutorial with SQLite (Create, Read, Update, Delete)

43
9



Welcome to this Android SQLite Database Tutorial video. This video shows How to use SQLite with android on Android Studio. In addition we will be Creating Database and Tables in our SQLite database for use in our android SQLite database tutorial. So I video Android SQLite Database Tutorial How to create a SqLite database and then Select, Insert, Update, Delete which correspond to CRUD functionality in SQLite database. SQLite database management system comes bundled with the Android OS.

00:01 # Introduction + Creating Database and Tables
24:30 # Insert values to SQLite Database table using Android
38:19 # Show SQLite Database table Values using Android
52:46 # Update values in SQLite Database table using Android
01:07:32 # Delete values in SQLite Database table using Android

SQLite is an open-source social database i.e. used to perform database operations on android gadgets, for example, putting away, controlling or recovering relentless information from the database.

#SQLite #Android #ProgrammingKnowledge
★★★Top Online Courses From ProgrammingKnowledge ★★★
Python Programming Course ➡️ ⚫️
Java Programming Course ➡️ ⚫️
Bash Shell Scripting Course ➡️ ⚫️
Linux Command Line Tutorials ➡️ ⚫️
C Programming Course ➡️ ⚫️
C++ Programming Course ➡️ ⚫️
PHP Programming Course ➡️ ⚫️
Android Development Course ➡️ ⚫️
C# Programming Course ➡️ ⚫️
JavaFx Programming Course ➡️ ⚫️
NodeJs Programming Course ➡️ ⚫️
Jenkins Course For Developers and DevOps ➡️ ⚫️
Scala Programming Tutorial Course ➡️ ⚫️
Bootstrap Responsive Web Design Tutorial ➡️ ⚫️
MongoDB Tutorial Course ➡️ ⚫️
QT C++ GUI Tutorial For Beginners ➡️

★★★ Online Courses to learn ★★★
Get 2 FREE Months of Unlimited Classes from skillshare –
Data Science – |
Machine Learning – |
Artificial Intelligence – |
MERN Stack E-Degree Program – |
DevOps E-degree – |
Data Analytics with R – |
AWS Certification Training – |
Projects in Java – |
Machine Learning With TensorFlow – |
Angular 8 – Complete Essential Guide –
Kotlin Android Development Masterclass –
Learn iOS Programming Building Advance Projects –

★★★ Follow ★★★
My Website –

DISCLAIMER: This video and description contains affiliate links, which means that if you click on one of the product links, I’ll receive a small commission. This help support the channel and allows us to continue to make videos like this. Thank you for the support!

Nguồn: https://chaoticpharmacology.com/

Xem thêm bài viết khác: https://chaoticpharmacology.com/cong-nghe/

43 COMMENTS

  1. if i want to perform or add where clause in Databasehelper's view all (Select statement ) what code should i use because i am confused.

  2. Please make a video for getting data from user through edit text like these fields in a row item quantity cost.. when the user entered data in a horizontal row item quantity and cost then the items display in list view….

  3. Tq so so so much.It was very helpful .The explanation was so clear and understandable .Keep on doing more videos.Tqsm sir

  4. Sir please make a tutorial send data first to data save in sqlite when Internet is off condition and after I connected to internet all save data in sqlite send to the server and after all sqlite data is empty in your device
    Thaks

  5. why my application stopped when i click on view button my is same as your code then why i have the problem like this and how can i fix it?@programmingknowledge

  6. Program worked perfectly for me. Thank you very much!
    Here is the Code Below:-

    /**************
    MainActivity.java
    *****************/

    public class MainActivity extends AppCompatActivity {

    DatabaseHelper myDb;

    EditText editTextId, editTextName, editTextMobile, editTextDescription;

    Button buttonAddData, buttonViewAllData, buttonUpdate, buttonDelete;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    init();

    addData();

    viewAllData();

    UpdateData();

    deleteData();

    }

    public void init(){

    myDb = new DatabaseHelper(this);

    editTextId = (EditText) findViewById(R.id.edtId);

    editTextName = (EditText) findViewById(R.id.edtName);

    editTextMobile = (EditText) findViewById(R.id.edtMobile);

    editTextDescription = (EditText) findViewById(R.id.edtDescription);

    buttonAddData = (Button) findViewById(R.id.btnAddData);

    buttonViewAllData = (Button) findViewById(R.id.btnViewAllData);

    buttonUpdate = (Button) findViewById(R.id.btnUpdate);

    buttonDelete = (Button) findViewById(R.id.btnDelete);

    }

    public void addData(){

    buttonAddData.setOnClickListener(new View.OnClickListener() {

    @Override

    public void onClick(View view) {

    String name, mobile, description;

    name = editTextName.getText().toString();

    mobile = editTextMobile.getText().toString();

    description = editTextDescription.getText().toString();

    boolean isInserted = myDb.insertData(name, mobile, description);

    if (isInserted = true)

    {

    Toast.makeText(MainActivity.this, "Data Inserted.", Toast.LENGTH_SHORT).show();

    }

    else Toast.makeText(MainActivity.this, "Data Not Inserted.", Toast.LENGTH_SHORT).show();

    }

    });

    }

    public void viewAllData(){

    buttonViewAllData.setOnClickListener(

    new View.OnClickListener() {

    @Override

    public void onClick(View view) {

    Cursor cursor = myDb.getAllData();

    if (cursor.getCount()==0)

    {

    //show message

    showMessage("Error", "No Data Found");

    return;

    }

    StringBuffer buffer = new StringBuffer();

    while (cursor.moveToNext())

    {

    buffer.append("ID: "+ cursor.getString(0) +"n");

    buffer.append("Name: "+ cursor.getString(1) +"n");

    buffer.append("Mobile: "+ cursor.getString(2) +"n");

    buffer.append("Description: "+ cursor.getString(3) +"nn");

    }

    //show all data

    showMessage("Data", buffer.toString());

    }

    }

    );

    }

    public void UpdateData(){

    buttonUpdate.setOnClickListener(new View.OnClickListener() {

    @Override

    public void onClick(View view) {

    String id, name, mobile, description;

    id = editTextId.getText().toString();

    name = editTextName.getText().toString();

    mobile = editTextMobile.getText().toString();

    description = editTextDescription.getText().toString();

    boolean isUpdated = myDb.updateData(id, name, mobile, description);

    if (isUpdated==true)

    {

    Toast.makeText(MainActivity.this, "Data Updated.", Toast.LENGTH_SHORT).show();

    }

    else Toast.makeText(MainActivity.this, "Data Not Updated.", Toast.LENGTH_SHORT).show();

    }

    });

    }

    public void deleteData(){

    buttonDelete.setOnClickListener(new View.OnClickListener() {

    @Override

    public void onClick(View view) {

    String id = editTextId.getText().toString();

    Integer deletedRows = myDb.deleteData(id);

    if (deletedRows > 0)

    {

    Toast.makeText(MainActivity.this, "Data Deleted.", Toast.LENGTH_SHORT).show();

    }

    else Toast.makeText(MainActivity.this, "Data Not Deleted.", Toast.LENGTH_SHORT).show();

    }

    });

    }

    public void showMessage(String title, String message){

    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    builder.setCancelable(true);

    builder.setTitle(title);

    builder.setMessage(message);

    builder.show();

    }

    }

    /******************
    DatabaseHelper.java
    *********************/

    public class DatabaseHelper extends SQLiteOpenHelper {

    public static final String DATABASE_NAME = "TailorRecords.db";

    public static final String TABLE_NAME = "Tailor_Table";

    public static final String COL_1 = "ID";

    public static final String COL_2 = "NAME";

    public static final String COL_3 = "MOBILE";

    public static final String COL_4 = "DESCRIPTION";

    public DatabaseHelper(Context context) {

    super(context, DATABASE_NAME, null, 1);

    }

    @Override

    public void onCreate(SQLiteDatabase db) {

    db.execSQL("create table " + TABLE_NAME +" (ID INTEGER PRIMARY KEY AUTOINCREMENT, " + "NAME TEXT, MOBILE TEXT, DESCRIPTION TEXT)");

    }

    @Override

    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);

    onCreate(db);

    }

    public boolean insertData(String name, String mobile, String description){

    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues contentValues = new ContentValues();

    contentValues.put(COL_2, name);

    contentValues.put(COL_3, mobile);

    contentValues.put(COL_4, description);

    long result = db.insert(TABLE_NAME, null, contentValues);

    if (result == -1)

    return false;

    else

    return true;

    }

    public Cursor getAllData()

    {

    SQLiteDatabase db = this.getWritableDatabase();

    Cursor cursor = db.rawQuery("select * from "+TABLE_NAME,null);

    return cursor;

    }

    public boolean updateData(String id, String name, String mobile, String description){

    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues contentValues = new ContentValues();

    contentValues.put(COL_1, id);

    contentValues.put(COL_2, name);

    contentValues.put(COL_3, mobile);

    contentValues.put(COL_4, description);

    db.update(TABLE_NAME, contentValues, "ID = ?", new String[]{id});

    return true;

    }

    public Integer deleteData(String id){

    SQLiteDatabase db = this.getWritableDatabase();

    return db.delete(TABLE_NAME,"ID = ?", new String[]{id});

    }

    }

    /***************
    activity_main.xml
    *****************/

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout

    xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    tools:context=".MainActivity"

    android:orientation="vertical">

    <EditText

    android:id="@+id/edtId"

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:hint="Enter ID"

    android:textSize="18sp"
    />

    <EditText

    android:id="@+id/edtName"

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:hint="Enter Name"

    android:textSize="18sp"
    />

    <EditText

    android:id="@+id/edtMobile"

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:hint="Enter Mobile Numer"

    android:textSize="18sp"/>

    <EditText

    android:id="@+id/edtDescription"

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:hint="Enter Description"

    android:textSize="18sp"/>

    <Button

    android:id="@+id/btnAddData"

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:textAllCaps="false"

    android:text="Add Data"/>

    <Button

    android:id="@+id/btnViewAllData"

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:textAllCaps="false"

    android:text="View All Data"/>

    <Button

    android:id="@+id/btnUpdate"

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:textAllCaps="false"

    android:text="Update"/>

    <Button

    android:id="@+id/btnDelete"

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:textAllCaps="false"

    android:text="Delete"/>

    </LinearLayout>

  7. Instead of checking db 19:12 thoroughly we can put toast in our constructor if that constructor will execute then toast will be printed successfully…..

  8. Can you expand this video (or go from this one) to show how to insert a date using SQLite? This video has been very helpful

  9. Thanks a ton! I learnt many things alongside the topic I came to watch for. Have a great time 🙌

  10. Video stupidly posted in June/2019 and it uses android studio version 1…. Now Android Studio ships with version 4. Crap video.

  11. Everything used in this video even Firefox and the extension are so outdated that I can't really keep up. Should have noticed earlier that it's almost a 5 years old video in fact.

LEAVE A REPLY

Please enter your comment!
Please enter your name here