I want to store Image into a SQLite Database in Blackberry.. so what i have to do?? I want to fetch images from server and then want to store in database.. I got images from server perfectly and store image as byte[] in database.. but i am not able to fetch it..
So plz help me…
Code edited into the question so it may be read:
try {
Statement st = db.createStatement("SELECT * FROM Image");
st.prepare();
Cursor c = st.getCursor();
Row r;
while(c.next()) {
r = c.getRow();
byte[] pic=r.getBlobBytes(0);
st.close();
EncodedImage _bmap = EncodedImage.createEncodedImage(pic, 0, pic.length);
BitmapField bmf=new BitmapField(_bmap.getBitmap());
add(bmf);
}
} catch ( Exception e ) {
System.out.println( e.getMessage() );
e.printStackTrace();
}
Your code doesn’t mention the name of the blob column, so I will call it
image_data. Something like this should work for insertion:For retrieval, explicitly naming the column may help, as your current code assumes the blob is always the first column in the table schema. Also, you shouldn’t close the statement in the loop, as this will block reading anything after the first image: