如何在Sqlite Android中更新Blob数据类型

时间:2018-02-13 06:29:58

标签: android arrays database sqlite blob

我想要更新Blob数据字段的朋友,其中列'IS NULL' 每当我尝试跟随代码时,它会生成错误 我只想知道如何更新Blob数据类型

"_id" : ObjectId("5694ba11b3957b7ff69c4547"),
"name" : "Okas 1",
"job" : {
    "name" : "job try1",
    "_id" : ObjectId("5a6ff9f7a336e3bba40a1d5c")
},
"categories" : {
    "ss" : [ 
        {
            "name" : "10",
            "_id" : ObjectId("5a6ff9f7a336e3bba40a1d5c")
        }, 
        {
            "name" : "8",
            "_id" : ObjectId("5a6ff9f7a336e3bba40a1d5f")
        },    
        {
             "name" : "800",
             "_id" : ObjectId("5a6ff9f7a336e3bba40a1d5a")
        }
    ]
}

当我尝试此代码时会生成此错误

        Bitmap icon = BitmapFactory.decodeResource(getResources(),R.drawable.audiobook);
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        icon.compress(Bitmap.CompressFormat.PNG,100,stream);
        simple = stream.toByteArray();
        String sql  = "UPDATE Settings SET image = "+simple+"where image IS NULL";
        db.execSQL(sql);

我做错了什么或我做错了什么???

2 个答案:

答案 0 :(得分:1)

String sql = "UPDATE Settings SET image = "+simple+" where image IS NULL"; 之前添加空格,如下所示:

DataTable

答案 1 :(得分:0)

卸下:

String sql  = "UPDATE Settings SET image = "+simple+"where image IS NULL";
db.execSQL(sql);

尝试使用ContentValues.put()SqliteDatabase.update()

ContentValues cv = new ContentValues();
cv.put("image", simple);
db.update("Settings", cv, "image is null", null);