Blob b=rs.getBlob(12);
bytes[] imagebytes=new bytes[(int)b.length()];
Image image;
image=getToolkit().createImage(imagebytes);
ImageIcon icon =new ImageIcon(image);
jLabel22.setIcon(icon);

This will not work. help me to display the image

Recommended Answers

All 3 Replies

Your second line creates a byte array of the right size, but you do not copy the data from the blob into that array, so the array is just full of zeros.
Use getBytes to convert the blob to a byte array (see the API dec for Blob for details).

and let's hope that the streaming of the image into the blob left it in a state where calling getBytes() on it would leave you with data that createImage() can interpret.

^ yes. Whatever encoding is used to convert the blob to an Image must be the inverse of whatever encoding was used to create the blob in the fist place.

You can also use blob.getBinaryStream() and use ImageIO to read from that if the blob was created by streaming as opposed to (eg) just getting the image's buffer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.