错误同时插入BLOB数据到Android上的SQLite [英] Error while inserting blob data into sqlite on android

查看:96
本文介绍了错误同时插入BLOB数据到Android上的SQLite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要BLOB数据存储到sqlite的,它增加了为imageData为空,虽然集团具有价值。我应该把集团的价值为SQL?

 字符串x = getResultAsOnlyValue(soapImage,外部数据);
字节[] =集团Base64.de code(X,Base64.DEFAULT);
BMP位图= BitmapFactory.de codeByteArray的(欧元区,0,bloc.length);
SQLiteStatement声明= db.compileStatement(插入ImageTable(为imageData)值()?);
statement.bindBlob(0,集团);
的Statement.execute();


解决方案

编辑:这个问题的答案

 字符串x = getResultAsOnlyValue(soapImage,外部数据);
字节[] =集团Base64.de code(X,Base64.DEFAULT);
BMP位图= BitmapFactory.de codeByteArray的(欧元区,0,bloc.length);
SQLiteDatabase分贝= getDb();
ContentValues​​值=新ContentValues​​();
values​​.put(的ImageData,集团);
db.insert(imageTable,空,价值);

在此操作,如果你得到NS_ERROR_FILE_CORRUPTED错误试图运行通过的SQLiteManager这意味着你需要升级你的分贝的SQLITE3分贝。 <一href=\"http://stackoverflow.com/questions/9409073/how-to-convert-sqlite2-to-sqlite3-and-what-are-the-differences-between-both-vers\">In此链接它会告诉你如何做到这一点。

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

解决方案

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.

这篇关于错误同时插入BLOB数据到Android上的SQLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆