I am trying to retrieve a blob(2) from my newly created embedded database and assign it to the image icon of a jlable (and of course save it back to the database if the image has been changed or altered).
I found the following code snippit from another site but am having probs getting it to work....

Blob blob1 = rs.getBlob("IMAGE");
IMAGE.setIcon(new ImageIcon(ByteStreams.toByteArray(blob1.getBinaryStream())));

Blob blob2 = rs.getBlob("POG");
POG.setIcon(new ImageIcon(ByteStreams.toByteArray(blob2.getBinaryStream())));

I am getting the error of cannot find symbol on ByteStreams
I know that I am missing something, ie defining the varible ByteStreams, but dont understand what is for or where/how to get the value for it.
Note: the images will vary in size from one to another.

recomendations to updating the database would be helpful as well....

3 Years
Discussion Span
Last Post by mKorbel

ByteStreams looks like a Google Java class.
I haven't tried this, but maybe you could try ImageIO.read(blob2.getBinaryStream()) to get the image then pass that to an ImageIcon constructor.


Is there something like that that works in reverse.... ie going from the image icon to the database blob?

maybe something like rs.updateBlob((ImageIcon) IMAGE.getIcon(), null);

(Know that this wont work)

Edited by mikewyatt


MikeWyatt: if there weren't, he wouldn't be able to get the image as blob from the db, now would he?
just google 'write image as blob java'. that'll give you enough of examples/tutorials.
but considering this is a different question, perhaps you should've started a new thread.


Did you get a solution to inputting from the blob? If so, how did that work? (ps It would be polite to let us know if you found a solution and, if so, what it was.)
Can you reverse it, eg write the Image to a ByteArrayOutputStream, then use that array in a call to the blob's setBytes method?

  • isn't logics for Input/OutputStream better for FileIO from database, maybe doesn't matted, but

  • you have to start to loading Image/BufferedImage, then to covert to ImageIcon/Icon (by test if is instanceof ImageIcon/Icon before)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.