Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
key_key
Posts: 59
Registered: ‎01-17-2011
My Device: 8520

How to store Bitmap into SQLite ?

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!

 

 

 

Please use plain text.
Developer
peter_strange
Posts: 19,608
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to store Bitmap into SQLite ?

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. 

Please use plain text.
New Contributor
kinjalshah_5320
Posts: 9
Registered: ‎07-02-2012
My Device: blackberry 9930,9900

Re: How to store Bitmap into SQLite ?

Hello.

 

I also want to store Image in Database.. so what i have to do?? plz help me..

Please use plain text.
Developer
peter_strange
Posts: 19,608
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to store Bitmap into SQLite ?

Have you tried BLOB?

Please use plain text.
New Contributor
kinjalshah_5320
Posts: 9
Registered: ‎07-02-2012
My Device: blackberry 9930,9900

Re: How to store Bitmap into SQLite ?

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..

Please use plain text.
New Contributor
kinjalshah_5320
Posts: 9
Registered: ‎07-02-2012
My Device: blackberry 9930,9900

Re: How to store Bitmap into SQLite ?

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

Please use plain text.
Contributor
Sukanya_Kalidoss
Posts: 24
Registered: ‎01-06-2014
My Device: 9220

Re: How to store Bitmap into SQLite ?

what is getImage method?

Please use plain text.
Developer
simon_hain
Posts: 16,207
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to store Bitmap into SQLite ?

obviously a custom method that returns an EncodedImage. If you want to add an image to a database you usually start with an image...
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
Sukanya_Kalidoss
Posts: 24
Registered: ‎01-06-2014
My Device: 9220

Re: How to store Bitmap into SQLite ?

 
Please use plain text.
Contributor
Sukanya_Kalidoss
Posts: 24
Registered: ‎01-06-2014
My Device: 9220

Re: How to store Bitmap into SQLite ?

It's storing as null value. Can u explain how to store the image in sqlite DB?

Please use plain text.