Android SQLite Database Tutorial 5 # Update values in SQLite Database table using Android

44
33



Find source-code here :

★★★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!

Android SQLite Update values
android sqlite update query
android sqlite update table
android sqlite update or insert
android sqlite update query not working
android sqlite update query example
android sqlite update all rows
android sqlite update where clause
android sqlite update or insert if not exists
Searches related to Show SQLite Database table Values using Android
Browse SQLite data on the Android emulator
Android SQLite database and content provider
Using SQLite Database with Android
how to create table in sqlite database in android
how to use sqlite database in android eclipse
android sqlite create database example

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

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

44 COMMENTS

  1. I suggest function updateData like below, it returns integer.
    public int updateData (String id, String name, String surname, String marks) {
    db = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(COL_1, id);
    contentValues.put(COL_2, name);
    contentValues.put(COL_3, surname);
    contentValues.put(COL_4, marks);
    String[] IDs = {id};
    return db.update(TBL_NAME, contentValues,"ID = ?",IDs); // successfull return 1 else return 0
    }
    Then on the calling method

    if (isUpdate == 1)
    Toast.makeText(MainActivity.this, "Data updated.", Toast.LENGTH_LONG).show();
    else
    Toast.makeText(MainActivity.this, "ID not found.nData not updated.", Toast.LENGTH_LONG).show();
    So if update succesfull the function updateData will return 1 else 0.

  2. Good example. However there is a bug in code.
    As is code in class DatabaseHelper.java =>
    public boolean updateData(…
    …etc..

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

    To be code in class DatabaseHelper.java =>
    public boolean updateData(…
    …etc..

    int lint =
    db.update(TABLE_NAME, contentValues, COL_1 + " = ?", new String[]{id});

    if (lint == 0) return false;
    else return true;

  3. The update doesn't work properly in case wrong id is inserted. It still shows updated successfully. To solve this, take result of db.update() in an int variable. Compare this value with 0, if it is greater than 0 return true else return false.

  4. thank you very much .. cool stuff there , i have question that why did you pass only id in string[ ] , why not all(name , surname etc) … i didn't get this

  5. Hai this is sainath can any one help me insert,Update and delete data in mssql database using android studio can any one reply me plzzz….

  6. Hi parogrammingKnowledge thank you very much for your video tutorial.I was appreciate if you could make in video call and in SMS messaging application. thank you again.

  7. just one question, when I put an ID that is not on my table, even though it does not update it still sends me "Data Updated Successfully", what would be the reason of this?

  8. I would like to display data on a list view rather than a message from string buffer. Could you please show me how ?

  9. respected sir i have a request that sir the tutorial vidio are not so much clear pic we don't understand that what coding is done sir please give me some suggestion that what i do sir i well be very thinkful of you sir

  10. Can U help me please with that… !!!
    android.database.sqlite.SQLiteException: no such column: ID (code 1): , while compiling: UPDATE student_table SET ID=?,NAME=?,SURNAME=?,MARKS=? WHERE ID= ?

  11. Hello! Thank you for this tutorial … I need to update a single value on a specific row … how could I do? Thanks!

  12. variable isUpdate will always have the value true because u have forced the method to return true, so by default, it is going to always return true even if the update is successful or not. Seems like, in that case, using Toast will confuse rather than helping with a message. You need to fix ur method.

  13. Hi ProgrammingKnowledge, Thank you very much for amazing Tutorial. I was wondering, if you could make tutorial on bottom bar? I tried to look for tutorials, but some how they dont work when applied in my app, I will really appreciate it 🙂

    Thank you 🙂

  14. i got this error:

    FATAL EXCEPTION: main
    Process: com.example.jesusalvelo.sqlite, PID: 2438
    android.database.sqlite.SQLiteException: near "fromstudent_table": syntax error (code 1): , while compiling: select * fromstudent_table

    could it be this part?
    public Cursor getAllData(){
    SQLiteDatabase db = this.getWritableDatabase();
    Cursor res = db.rawQuery("select * from"+TABLE_NAME,null);
    return res;
    }

  15. AS 2.2.1 is so awesome and powerful that following source codes are given automatically:
    public Cursor getAllData() {
    SQLiteDatabase db = this.getWritableDatabase();
    Cursor res = db.rawQuery("select * from "+TABLE_NAME,null);
    return res;
    }

    public boolean updateData(String id,String name,String surname,String marks) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(COL_1,id);
    contentValues.put(COL_2,name);
    contentValues.put(COL_3,surname);
    contentValues.put(COL_4,marks);
    db.update(TABLE_NAME, contentValues, "ID = ?",new String[] { id });
    return true;

  16. My emulator does not start and neither my mobile is root so i cant see the table. Is there another way to see the table? Please help me.

LEAVE A REPLY

Please enter your comment!
Please enter your name here