首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Sqlite中更新Blob数据类型

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

Stack Overflow用户
提问于 2018-02-13 06:29:58
回答 2查看 1K关注 0票数 0

朋友们,我想更新Blob数据字段,其中列‘是空’,每当我尝试下面的代码时,它都会产生错误,我只想知道如何更新Blob ??

代码语言:javascript
复制
        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);

当我尝试这个代码时,它会生成这个错误。

代码语言:javascript
复制
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.blackhat.rhythmbox/com.blackhat.rhythmbox.Welcome}: android.database.sqlite.SQLiteException: unrecognized token: ":" (code 1): , while compiling: UPDATE Settings SET image = :[B@27a97db7
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2521)
 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2601)
 at android.app.ActivityThread.access$800(ActivityThread.java:178)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
 at android.os.Handler.dispatchMessage(Handler.java:111)
 at android.os.Looper.loop(Looper.java:194)
 at android.app.ActivityThread.main(ActivityThread.java:5637)
 at java.lang.reflect.Method.invoke(Native Method)
 at java.lang.reflect.Method.invoke(Method.java:372)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: android.database.sqlite.SQLiteException: unrecognized token: ":" (code 1): , while compiling: UPDATE Settings SET image = :[B@27a97db7
 at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
 at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:898)
 at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:509)
 at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
 at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
 at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
 at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1704)
 at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1635)
 at com.blackhat.rhythmbox.Welcome.addtoDatabase(Welcome.java:124)
 at com.blackhat.rhythmbox.Welcome.code(Welcome.java:67)
 at com.blackhat.rhythmbox.Welcome.onCreate(Welcome.java:57)
 at android.app.Activity.performCreate(Activity.java:6100)
 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2601) 
 at android.app.ActivityThread.access$800(ActivityThread.java:178) 
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470) 
 at android.os.Handler.dispatchMessage(Handler.java:111) 
 at android.os.Looper.loop(Looper.java:194) 
 at android.app.ActivityThread.main(ActivityThread.java:5637) 
 at java.lang.reflect.Method.invoke(Native Method) 
 at java.lang.reflect.Method.invoke(Method.java:372) 
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960) 
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-02-13 07:07:57

移除:

代码语言:javascript
复制
String sql  = "UPDATE Settings SET image = "+simple+"where image IS NULL";
db.execSQL(sql);

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

代码语言:javascript
复制
ContentValues cv = new ContentValues();
cv.put("image", simple);
db.update("Settings", cv, "image is null", null);
票数 0
EN

Stack Overflow用户

发布于 2018-02-13 06:35:38

where之前添加如下空格:

代码语言:javascript
复制
String sql  = "UPDATE Settings SET image = "+simple+" where image IS NULL";
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48760724

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档