I\'m trying to display images retrieve from MySQL database of blob datatype. Could not figure out what is the problem that causes the image column to display data like this
Since you used preparedstatement.setBlob(1, InputStream);
to store the image, I have to assume that you stored the physical image file/format and not just the pixel data.
You need to read back this image format and convert to a supported image format for Swing/Java.
Start by getting a Blob
reference to the database field...
Blob blob = rs.getBlob(1);
Once you have a Blob
, you can use it's binary InputStream
and read the data...
BufferedImage image = null;
try (InputStream is = blob.getBinaryStream()) {
image = ImageIO.read(is);
} catch (IOException exp) {
exp.printStackTrace();
}
Now, you can make it an ImageIcon
using new ImageIcon(image)
and put this within your table model...