Please help me to retrieve image I saved as #blob
in #mysql
database
This is my code I used for saving the image
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(null);
File f = chooser.getSelectedFile();
filename =f.getAbsolutePath();
ImageIcon imageIcon = new ImageIcon(new ImageIcon(filename).getImage().getScaledInstance(lbl_img.getWidth(), lbl_img.getHeight(), Image.SCALE_DEFAULT));
lbl_img.setIcon(imageIcon);
try {
File image = new File(filename);
FileInputStream fis = new FileInputStream (image);
ByteArrayOutputStream bos= new ByteArrayOutputStream();
byte[] buf = new byte[1024];
for(int readNum; (readNum=fis.read(buf))!=-1; ){
bos.write(buf,0,readNum);
}
person_image=bos.toByteArray();
}
catch(Exception e){
JOptionPane.showMessageDialog(null,e.getMessage());
}
But when I try to retrieve my image using
byte[] img = rs.getBytes("IMAGE");
ImageIcon imageIcon = new ImageIcon(new ImageIcon(img).getImage().getScaledInstance(lbl_image.getWidth(), lbl_image.getHeight(), Image.SCALE_SMOOTH));
lbl_image.setIcon(imageIcon);
It doesn't give any error, yet it doesn't retrieve the image. Please help me to sort out where the problem is