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
  2.  
  3.          db.execSQL("CREATE TABLE IF NOT EXISTS "+dbTable+"(image BLOB);");
  4.  
  5. //getting a sample image from drawable folder inside my project
  6.  
  7.          InputStream xmlInputStream = this.getResources().openRawResource(R.drawable.abc);
  8.  
  9. //convert it into a byte[]
  10.  
  11.          byte[] bb = (xmlInputStream.toString()).getBytes();
  12.  
  13. //try inserting the byte into sqlite
  14.  
  15.          db.execSQL("INSERT INTO "+ dbTable + "(image)" + " VALUES (\""+bb+"\");");    
  16.  
  17.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


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
Rahul
Experienced Developer
Experienced Developer
 
Posts: 89
Joined: Wed Oct 01, 2008 11:16 am

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 3 guests