-2

I am learning Android now....I am trying to use SQLite in my application. I am inserting data in table without hassle with below code

public void addQuote(String qu_text, int qu_author, int qu_web_id, String qu_time, int qu_like, int qu_share) {
            open();
            ContentValues v = new ContentValues();
            v.put(QU_TEXT, qu_text);        
            v.put(QU_AUTHOR, qu_author);
            v.put(QU_FAVORITE, "0");        
            v.put(QU_WEB_ID, qu_web_id);
            v.put(QU_TIME, qu_time);
            v.put(QU_LIKE, qu_like);
            v.put(QU_SHARE, qu_share);

            database.insert(TABLE_QUOTES, null, v);

        }

Now I want make another function which can update two column in table called qu_like and qu_share. anyone can please suggest me how can I update only two column instead of full table ?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • please clarify: If you are talking about update a column, do you mean specific entries of a row or all rows inside a column? If we are talking about a row, it´s the horizontal line, a column is the vertical line of a table.. – Opiatefuchs May 22 '17 at 07:20
  • @Opiatefuchs I want update all row from that colums – Priya Patel May 22 '17 at 07:23
  • Syntax for an `execSQL()` instruction: `UPDATE myTable SET Column1 = value1, Column2 = value2 WHERE condition`. Remove the WHERE condition, to update all the rows in your table. And please study some basic SQL. – Phantômaxx May 22 '17 at 07:23
  • 1
    have you tried something atleast....[Here is similar question](http://stackoverflow.com/questions/9798473/sqlite-in-android-how-to-update-a-specific-row) – ELITE May 22 '17 at 07:32

2 Answers2

0

You can use this method.

public void updateQuote(long qu_id, int qu_like, int qu_share) {
            open();
            ContentValues v = new ContentValues();
            v.put(QU_LIKE, qu_like);
            v.put(QU_SHARE, qu_share);

            database.update(TABLE_QUOTES, v, "qu_id=" + qu_id, null);

        }
Lubomir Babev
  • 1,892
  • 1
  • 12
  • 14
0

you can try something like that

public void updateRecord(String[] title, long id) {

    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues cv = new ContentValues();

    cv.put(QU_LIKE, title[0]);
    cv.put(QU_LIKE,title[1]);

    db.update(DATABASE_TABLE_NAME, cv, "qu_id" + "=" + id, null);

    db.close();
}
Ali Ahsan
  • 460
  • 3
  • 13