views:

279

answers:

2

Hi, I can not find useful code for how storing the images into BLOB ,please help me with some code and also can I show those images from MySQL to my desktop pane in GUI?

+1  A: 

Easiest way is to store the contents of some binary image file in the blob, extract them, write them to a file and open that file with an image file parser of some kind. Or, if you're really tricky, use that same image parser to read the data from memory directly after pulling the blob out of the DB.

I'm assuming you've got some sort of ImagePane widget that can handle the GUI display if you can provide an image file to it.

Drew Hall
+1  A: 

If the image is located on your MySQL host, you could use the LOAD_FILE() command for storing an image in a BLOB:

-- Using the following table as an example:
CREATE TABLE MyTable (
   image  BLOB
);

-- This will insert a file in a BLOB column.
INSERT INTO MyTable (image) VALUES(LOAD_FILE('/tmp/image.png'));

Make sure that the image file is readable by MySQL, and also make sure that your MySQL user has the FILE privilege.

To grant the FILE privilege, log-in as root and execute:

GRANT FILE ON *.* TO 'mysql_user'@'localhost';
Daniel Vassallo