Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite update query Android

Tags:

java

android

sql

The table contains 4 columns : rowID , word , defintition , group_id

I want to change a certain row's word and definition . So here is my code (word is an object where the word , definition , id and the group_id are stored)

   ContentValues values = new ContentValues();
    values.put(KEY_WORD, word.getWord());
    values.put(KEY_DEFINITION, word.getDefinition());
    db.update(TABLE_WORDS, values, KEY_ID, new String [] {String.valueOf(word.getID())});

Can anyone tell me why it only creates a new line instead of changing the row under given ID ?

like image 384
user3199577 Avatar asked Jan 16 '14 13:01

user3199577


3 Answers

   String id = "1";
   SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(COLUMN_NOTIFICATION_STATUS,"canceled");
    db.update(TABLE_NOTIFICATION, values,COLUMN_NOTIFICATION_ID + " = ? ",new String[]{ String.valueOf(id) });

it will work as prepared statement. this piece of code worked in my case .. Thanks

like image 182
Fazal Avatar answered Oct 06 '22 23:10

Fazal


SQLiteDatabase db = this.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(KEY_NAME, contact.getName());
        values.put(KEY_DATE, contact.getDate());

        // updating row
        return db.update(TABLE_CONTACTS, values, KEY_ID + " = ?",
                new String[] { String.valueOf(contact.getID()) });
like image 23
Digvesh Patel Avatar answered Oct 07 '22 00:10

Digvesh Patel


this work for me, while db.rawquery didnot work.

output query

String qu="UPDATE "+ DATABASE_TABLE_DATA + " SET "+isbookmark+" = "+status+" WHERE id = "+uid+";";
db.execSQL(qu);

output query :
UPDATE tabel_data SET `isbookmark` = 1 WHERE id = 2720271;
like image 38
Muklas Avatar answered Oct 07 '22 00:10

Muklas