繁体   English   中英

在Android上将Blob数据插入sqlite时出错

[英]Error while inserting blob data into sqlite on android

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

编辑:对问题的答复

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运行数据库时遇到NS_ERROR_FILE_CORRUPTED错误,则意味着您需要将数据库升级到sqlite3。 在此链接中,它告诉您如何执行此操作。

早上好,请尝试以下答案: 将Drawable转换为BLOB数据类型

我认为这就是您要寻找的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM