I want to update a row in sqlite. My query looks like this
update name="aaa",publisher="ppp",price="111" where bookid=5 and booktype="comic"
I want to update by using the following update command .
int android.database.sqlite.SQLiteDatabase.update(String table, ContentValues values, String whereClause, String[] whereArgs)
What should be the parameters for "whereClause" and "whereArgs". I am searching in Internet but I am not getting related examples. please help me.
4 Answers4
You can update it using this code:
DatabaseCreator.class:
public class DatabaseCreator extends SQLiteOpenHelper{ private static final String DB_NAME="database_name"; private static final int DB_VER=1; private static final String TABLE_NAME="<table creation query>"; public DatabaseCreator(Context context) { super(context,DB_NAME, null, DB_VER); } @Override public void onCreate(SQLiteDatabase database) { database.execSQL(TABLE_NAME); } @Override public void onUpgrade(SQLiteDatabase database, int arg1, int arg2) { database.execSQL("DROP TABLE IF EXISTS table_name"); onCreate(database); }}Now use below code where you need to update the row:
DatabaseCreator dbcreator=new DatabaseCreator(context);SQLiteDatabase sqdb=dbcreator.getWritableDatabase();ContentValues values=new ContentValues();values.put("name","aaa");values.put("publisher","ppp");values.put("price","111");int id=sqdb.update("table_name",values,"bookid='5' and booktype='comic'",null);5 Comments
Try this. It could helpful for you
db.execSQL("UPDATE DB_TABLE SET YOUR_COLUMN='newValue' WHERE id=6 ");or
ContentValues newValues = new ContentValues();newValues.put("YOUR_COLUMN", "newValue");or
ContentValues newValues = new ContentValues();newValues.put("YOUR_COLUMN", "newValue");String[] args = new String[]{"user1", "user2"};db.update("YOUR_TABLE", newValues, "name=? OR name=?", args);Comments
use this code
public void updatefriendpic(String fuid, String temp, String temp1) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(THUMB_FRIEND, temp); values.put(CONTENT_FRIEND, temp1); // update Row db.update(TABLE_FRIEND_LIST,values,"_id = '"+fuid+"'",null); db.close(); // Closing database connection Log.d(TAG, "New user update into sqlite: "); }Comments
public boolean updateStopnameOfRute(String route,String stopname,int sequence) { DATABASE_TABLE = "tbl_Stop"; ContentValues contentvalue=new ContentValues(); contentvalue.put("stop_name", stopname); return db.update(DATABASE_TABLE, contentvalue, "route_name='"+route+"'" +"and"+ "stop_sequence="+sequence, null)>0; }Comments
Explore related questions
See similar questions with these tags.



