Reputation: 441
I have successfully added a blob file into my database. but when i try to update it gives errors. I tried two methods here is my code.I searched but everywhere i found adding in database not updating a byte[].
1- First i tried to save simple pro byte[]. but it said it didn't recognize the value of byte[].
2- Then i tried Arrays.toString(pro) but no such column.
public void profile(String status,byte[] pro, SQLiteDatabase db){
ContentValues sv = new ContentValues();
sv.put(mDatabase.Tableinfo.status, status);
sv.put(mDatabase.Tableinfo.Pic, pro) ;
db.update(mDatabase.Tableinfo.Table_Name, sv, mDatabase.Tableinfo.status + "=" + status + " and " + mDatabase.Tableinfo.Pic + "=" + Arrays.toString(pro), null);
// db.insert(mDatabase.Tableinfo.Table_Name, null, sv);
android.database.sqlite.SQLiteException: near "and": syntax error (code 1): , while compiling: UPDATE User SET status=?,Pro_pic=? WHERE status= and Pro_pic=[-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 120, 0, 0, 0, 1............ and to infinite .
You would probably suggest this but I even tried this but can't add a byte[] into String array.
mDatabase.Tableinfo.status + "=? and " +mDatabase.Tableinfo.Pic +"=?", new String[]{status,pro(this is a byte array)}, null);
Upvotes: 0
Views: 815
Reputation: 441
Note - I have only one row So just doing this solved my problem. No selection no other things.
db.update(mDatabase.Tableinfo.Table_Name, sv,null, null);
Upvotes: 1
Reputation: 123
Add single quotation marks may works
db.update(mDatabase.Tableinfo.Table_Name, sv, mDatabase.Tableinfo.status "="
+ status + " and " + mDatabase.Tableinfo.Pic + "= '"+Arrays.toString(pro)+"'", null);
Upvotes: 1