Priya Patel Priya Patel - 1 year ago 51
Java Question

Update Column in SQLlite

I am learning android now....I am trying to use sqllite 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 ?

Answer Source

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);

        }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download