Retrieve image saved in a database with mysql in java

0

Cordial greeting.

I need to show me the image in jlabel , the image is already saved in the database, and when I click on the consult button I need you to bring it back and it does not, there is the code that I am trying to implement, I use eclipse.

 try {


              java.sql.Connection conexion=DriverManager.getConnection("jdbc:mysql://localhost/bdpro","root" ,"");
              java.sql.Statement comando=conexion.createStatement();
              ResultSet registro = comando.executeQuery("select nombre,precio,fecha,foto from tablapro  where id="+textField.getText());
              if (registro.next()==true) {

                  textField_1.setText(registro.getString("nombre"));
                  textField_2.setText(registro.getString("precio"));
                  Date Estado = registro.getDate("fecha");                    
                  dateChooser.setDate(Estado);


                  Blob Blob = (Blob) registro.getBlob(4);
                  byte[] imageByte = Blob.getBytes(1, (int) Blob.length()); 
                  InputStream is=new ByteArrayInputStream(imageByte); 
                  BufferedImage imag=ImageIO.read(is); 
                  Image image=Toolkit.getDefaultToolkit().createImage(imageByte);


                  ImageIcon  icono = new ImageIcon(image);
                  lblFoto.setIcon(TamañoImg(null,icono));


               }


              conexion.close();
            } catch(SQLException | IOException ex){
                JOptionPane.showMessageDialog(null, ex.getMessage());
            }
    
asked by Jhader Castellar T 14.12.2018 в 22:22
source

0 answers