Error while inserting blob data into sqlite on android

牧云@^-^@ 提交于 2019-12-08 05:45:54

问题


I want to store blob data into sqlite, It adds imageData as null although bloc has value. What should I put bloc value into sql?

String x = getResultAsOnlyValue("soapImage", xdata);
byte[] bloc = Base64.decode(x, Base64.DEFAULT);
Bitmap bmp = BitmapFactory.decodeByteArray(bloc,0,bloc.length);
SQLiteStatement statement =  db.compileStatement("insert into ImageTable (imageData) values(?)"); 
statement.bindBlob(0, bloc); 
statement.execute();

回答1:


EDITED: ANSWER TO THE QUESTION

String x = getResultAsOnlyValue("soapImage", xdata);
byte[] bloc = Base64.decode(x, Base64.DEFAULT);
Bitmap bmp = BitmapFactory.decodeByteArray(bloc,0,bloc.length);
SQLiteDatabase db = getDb();
ContentValues values = new ContentValues();
values.put("ImageData", bloc);
db.insert("imageTable", null, values);

After this operation if you get NS_ERROR_FILE_CORRUPTED error while trying to run the db via sqlitemanager that means you need to upgrade your db to sqlite3. In this link it tells you to how to do this.




回答2:


Good morning, try this answer out: Convert Drawable to BLOB Datatype

I think it's what you're looking for.



来源:https://stackoverflow.com/questions/9395755/error-while-inserting-blob-data-into-sqlite-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!