10-17-2011 05:07 AM
Hello friends,
I want to store a bitmap into SQLite database.
query for that create a table structure as follow.
"CREATE TABLE card_table ('card_id' INTEGER PRIMARY KEY,'picture' BLOB)"
for storing a Bitmap convert bitmap into byte array and then i store
so it gives an exception out of memory.
But i am not able to store a Bitmap into table.
Please help me!
10-17-2011 06:40 AM
I am not familiar with storing BLOBS in SQL, but if you wanted to convert the Bitmap to bytes yourself, you could use something like JPEGEncodedImage.encode(..) to do it, then do a getData to get the bytes.
07-28-2012 02:28 AM
Hello.
I also want to store Image in Database.. so what i have to do?? plz help me..
07-28-2012 04:27 AM
Have you tried BLOB?
07-28-2012 05:01 AM
Yes, i tried it.. and i pass byte[ ] in insert query.. bt it will not work..
d = DatabaseFactory.open(uri);
Statement st = d.createStatement(
"INSERT INTO img(Name,picture) " +
"VALUES ('"+name+"','"+pic+"')");
st.prepare();
st.bind(1, name);
st.bind(2, pic);
st.execute();
st.close();
d.close();
bt data is not inserted in database..
07-31-2012 02:20 AM
Hey I got solution..and its work perfectly fine..
For inserting,
EncodedImage pic = getImage();
byte [] imageBytes = pic.getData();
Statement st = db.createStatement("INSERT INTO Image (image_data) values (?)");
st.prepare();
st.bind(1, imageBytes);
st.execute();
And for Fetching,
Statement st = db.createStatement("SELECT image_data FROM Image");
st.prepare();
Cursor c = st.getCursor();
Row r;
while(c.next()){
r = c.getRow();
byte[] pic=r.getBlobBytes(0);
EncodedImage _bmap = EncodedImage.createEncodedImage(pic,0, pic.length);
BitmapField bmf=new BitmapField(_bmap.getBitmap());
add(bmf);
}
st.close(); // moved this line out of the loop