storing images as blob in sqlite

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

storing images as blob in sqlite

Postby Rahul » Fri Feb 27, 2009 4:33 pm

I am currently trying to store an image into the sqlite database as a blob and i am retrieve it back.I am not sure if this is the correct approach since i dint find much of sample codes related to inserting images in sqlite.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. //creating blob datatype
  3.          db.execSQL("CREATE TABLE IF NOT EXISTS "+dbTable+"(image BLOB);");
  5. //getting a sample image from drawable folder inside my project
  7.          InputStream xmlInputStream = this.getResources().openRawResource(;
  9. //convert it into a byte[]
  11.          byte[] bb = (xmlInputStream.toString()).getBytes();
  13. //try inserting the byte into sqlite
  15.          db.execSQL("INSERT INTO "+ dbTable + "(image)" + " VALUES (\""+bb+"\");");    
Parsed in 0.012 seconds, using GeSHi

I am able to insert values but when i try retrieving them as byte using decodeByteArray it gives me the following error.

DEBUG/skia(13003): xxxxxxxxxxx jpeg error 53 Not a JPEG file: starts with 0x%02x 0x%02x

The image retrieving query works fine as i have checked retrieving an image previously stored as blob on a sample database.

I have tried storing and retrieving different image files but i am getting the same error.Could any one tell me as how to solve this problem
Experienced Developer
Experienced Developer
Posts: 89
Joined: Wed Oct 01, 2008 11:16 am


Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 3 guests