简体   繁体   English

在Android Sqlite数据库中更新byte []

[英]Updating a byte[] in Android Sqlite Database

I have successfully added a blob file into my database. 我已成功将blob文件添加到数据库中。 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[]. 我尝试了两种方法,这是我的代码。我进行了搜索,但是发现到数据库的任何地方都没有更新byte []。

1- First i tried to save simple pro byte[]. 1-首先,我尝试保存简单的pro byte []。 but it said it didn't recognize the value of byte[]. 但它表示无法识别byte []的值。

2- Then i tried Arrays.toString(pro) but no such column. 2-然后我尝试了Arrays.toString(pro),但是没有这样的列。

      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. 您可能会建议这样做,但我什至尝试过,但无法将byte []添加到String数组中。

  mDatabase.Tableinfo.status + "=? and " +mDatabase.Tableinfo.Pic +"=?", new String[]{status,pro(this is a byte array)}, null);

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM