Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite update a column based on where clause android

I am developing an android app, where I want to update a column in a row based on a where clause which comprises of two values. Below is what I have tried.

public void setlocationsetcolumn(double lats , double longs, String setvalue)
{
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();

    values.put(Loc_set, setvalue);

    db.update(TABLE_LATLONG, values, " WHERE "+Loc_lati +" = " + lats+" AND "+Loc_longi+" = "+longs, null);
}

I wan to update the Loc_set, based on the lats & longs values. but i am getting a force close. Am I doing something wrong here. Please help.Thanks!

like image 342
Dave Avatar asked Oct 01 '13 12:10

Dave


2 Answers

below snippet will help you.

String[] args = new String[]{lats, longs};
db.update(TABLE_LATLONG, values, "Loc_lati=? AND Loc_longi=?", args);
like image 160
Vipul Avatar answered Oct 04 '22 00:10

Vipul


Drop the WHERE String . Try this :

db.update(TABLE_LATLONG, values, Loc_lati +" = " + lats+" AND "+Loc_longi+" = "+longs, null);

However, I Don't know what loc_lati and loc_longi are, hopefully columns in your db.

like image 28
hordurh Avatar answered Oct 04 '22 01:10

hordurh