Mustafa Güven
Mustafa Güven

Reputation: 15744

Error while inserting blob data into sqlite on android

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

Upvotes: 1

Views: 2241

Answers (2)

Mustafa Güven
Mustafa Güven

Reputation: 15744

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.

Upvotes: 1

dbDev
dbDev

Reputation: 1549

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

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

Upvotes: 0

Related Questions