I have a connection with a MySQL database, and I try to resolve a issue which appear when the blob (image) extracted from database don't render correctly into a JDialog (see screenshot). Note: I have multiple images (size ~50-60 Kb), some of them appear correctly (full), but some of them appear not-fully loaded. I tried to re-save and insert the image into MySQL, but the issue persist.
Any ideas?
My code is:
MenuItemPhoto.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
try {
String sql = "select photo from RDSSPhoto where id ='38'";
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
if (rs.next()) {
byte[] imagedata = rs.getBytes("photo");
format = new ImageIcon(imagedata);
JOptionPane pane = new JOptionPane((Frame) null, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION);
JDialog d = pane.createDialog((Frame) null, "Photo");
pane.setIcon(format);
if (!d.isVisible()) {
d.setLocationRelativeTo(RDSSView.this);
d.pack();
}
d.setVisible(true);
}
} catch (Exception e) {
e.printStackTrace();
}
}
});