Reputation: 1159
Friends I want to Update Blob Data Field where Column 'IS NULL' whenever i try following code it generates error I just want to know How To Update Blob Datatype ??
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);
when I try this code it generates this error
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)
where i doing wrong or what i am doing wrong ???
Upvotes: 0
Views: 1256
Reputation: 1268
Remove:
String sql = "UPDATE Settings SET image = "+simple+"where image IS NULL";
db.execSQL(sql);
Try using ContentValues.put()
and SqliteDatabase.update()
ContentValues cv = new ContentValues();
cv.put("image", simple);
db.update("Settings", cv, "image is null", null);
Upvotes: 0
Reputation: 8315
add space before where
like this:
String sql = "UPDATE Settings SET image = "+simple+" where image IS NULL";
Upvotes: 1