在blob上将blob数据插入sqlite时出错

时间:2012-02-22 13:29:13

标签: android sqlite blob

我想将blob数据存储到sqlite中,它将imageData添加为null,尽管bloc具有值。我该怎么把bloc值放到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();

2 个答案:

答案 0 :(得分:1)

已编辑:对问题的回答

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

执行此操作后,如果在尝试通过sqlitemanager运行db时遇到NS_ERROR_FILE_CORRUPTED错误,则表示您需要将db升级到sqlite3。 In this link它告诉你如何做到这一点。

答案 1 :(得分:0)

早上好,请尝试这个答案:Convert Drawable to BLOB Datatype

我认为这就是你要找的东西。