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
Developer
Blanc
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Insert Image into SQLite

Hi all,

 

am working on 5.0. i need to save an image to the sqlite database. how can i make that?

 

is it possible to save the image in sqlite for blackberry? what are the supporting data formats?

Thanks and Regards,
PraveenGoparaju.
Developer
Blanc
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: Insert Image into SQLite

any ideas!!!!

Thanks and Regards,
PraveenGoparaju.
Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.997 Dev OS, Z30 (STA100-5)-10.3.1.997 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: Insert Image into SQLite

I have never used the database classes so this might not work but from what I suppose is the class you use to store data (Statement?) you could save the image as an array of bytes.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
New Contributor
kinjalshah_5320
Posts: 9
Registered: ‎07-02-2012
My Device: blackberry 9930,9900

Re: Insert Image into SQLite

Hey i also want to store image into Database...

Have you got solution?

Plz help me..I am new to Blackberry..

New Contributor
kinjalshah_5320
Posts: 9
Registered: ‎07-02-2012
My Device: blackberry 9930,9900

Re: Insert Image 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

Developer
kamal_nigam
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10

Re: Insert Image into SQLite

Use byte array to store data.

Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.