NETBEANS - JAVA - DERBY - Error retrieving byte for ImageIcon

1

Save everything good? I stored a BLOB file and I'm looking to recover it, it's a JPG.

Below is the ResultSet of it:

        byte[] bin = null; // (2)

        ResultSet rs;                
            try {

                rs = produtoControle.escolha(buscar.getText());    
                    while(rs.next()){                            
                        lblNumId.setText(rs.getString("codigo"));
                        tfNome.setText(rs.getString("nome_produto"));
                        cbCategoria.setSelectedItem(String.valueOf(rs.getString("categoria")));
                        tfQuantidade.setText(rs.getString("quantidade"));
                        tfPreco.setText(rs.getString("preco"));
                        tfFabDist.setText(rs.getString("fabricante"));
                        tfResponsavel.setText(rs.getString("responsavel"));
                        tftTelefone.setText(rs.getString("telefone"));
                        tfEmail.setText(rs.getString("email"));
                        taInfo.setText(rs.getString("informacoes"));

                        bin = rs.getBytes("imagem");
                    }

                    ByteArrayInputStream bis = new ByteArrayInputStream(bin);
                    Iterator <?> readers = ImageIO.getImageReadersByFormatName("jpg");// (2)

                    ImageReader reader = (ImageReader) readers.next();
                    Object source = bis;
                    ImageInputStream iis; 
            try {
                iis = ImageIO.createImageInputStream(source);
                reader.setInput(iis, true);
                ImageReadParam param = reader.getDefaultReadParam();
                Image imagem = reader.read(0, param);
                foto.setIcon(new ImageIcon(imagem.getScaledInstance(foto.getWidth(), foto.getHeight(), imagem.SCALE_DEFAULT)));
            } catch (IOException ex) {
                Logger.getLogger(InterfaceProduto.class.getName()).log(Level.SEVERE, null, ex);
            }                        
                    if("".equals(lblNumId.getText())){
                        fechaConexao();
                        return;
                    }
    } catch (SQLException ex) {
        Logger.getLogger(InterfaceProduto.class.getName()).log(Level.SEVERE, null, ex);
    }   
        ValidaCampos("novo");
           btSalvar.setText("Alterar");
            btExcluir.setEnabled(true);
            fechaConexao();
}        

And the following error occurs when stamping the same in JLABEL:

debug: Nov 26, 2017 10:41:44 PM view.InterfaceProducto buscarKeyPressed SERIOUS: null javax.imageio.IIOException: Not a JPEG file: starts with 0xac 0xed     at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImageHeader (Native Method)     at com.sun.imageio.plugins.jpeg.JPEGImageReader.readNativeHeader (JPEGImageReader.java:620)     at com.sun.imageio.plugins.jpeg.JPEGImageReader.checkTablesOnly (JPEGImageReader.java:347)     at com.sun.imageio.plugins.jpeg.JPEGImageReader.gotoImage (JPEGImageReader.java:492)     at com.sun.imageio.plugins.jpeg.JPEGImageReader.readHeader (JPEGImageReader.java:613)     at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal (JPEGImageReader.java:1070)     at com.sun.imageio.plugins.jpeg.JPEGImageReader.read (JPEGImageReader.java:1050)     at view.ProductInterface.searchKeyPressed (ProductProduct.java:542)     at view.InterfaceProduct.access $ 600 (ProductProduct.java:63)     at view.ProductInterface $ 8.keyPressed (ProductProduct.java:301)     at java.awt.Component.processKeyEvent (Component.java:6491)     at javax.swing.JComponent.processKeyEvent (JComponent.java:2832)     at java.awt.Component.processEvent (Component.java:6310)     at java.awt.Container.processEvent (Container.java:2236)     at java.awt.Component.dispatchEventImpl (Component.java:4889)     at java.awt.Container.dispatchEventImpl (Container.java:2294)     at java.awt.Component.dispatchEvent (Component.java:4711)     at java.awt.KeyboardFocusManager.redispatchEvent (KeyboardFocusManager.java:1954)     at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent (DefaultKeyboardFocusManager.java:806)     at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent (DefaultKeyboardFocusManager.java:1074)     at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions (DefaultKeyboardFocusManager.java:945)     at java.awt.DefaultKeyboardFocusManager.dispatchEvent (DefaultKeyboardFocusManager.java:771)     at java.awt.Component.dispatchEventImpl (Component.java:4760)     at java.awt.Container.dispatchEventImpl (Container.java:2294)     at java.awt.Window.dispatchEventImpl (Window.java:2746)     at java.awt.Component.dispatchEvent (Component.java:4711)     at java.awt.EventQueue.dispatchEventImpl (EventQueue.java:758)     at java.awt.EventQueue.access $ 500 (EventQueue.java:97)     at java.awt.EventQueue $ 3.run (EventQueue.java:709)     at java.awt.EventQueue $ 3.run (EventQueue.java:703)     at java.security.AccessController.doPrivileged (Native Method)     at java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege (ProtectionDomain.java:80)     at java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege (ProtectionDomain.java:90)     at java.awt.EventQueue $ 4.run (EventQueue.java:731)     at java.awt.EventQueue $ 4.run (EventQueue.java:729)     at java.security.AccessController.doPrivileged (Native Method)     at java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege (ProtectionDomain.java:80)     at java.awt.EventQueue.dispatchEvent (EventQueue.java:728)     at java.awt.EventDispatchThread.pumpOneEventForFilters (EventDispatchThread.java:201)     at java.awt.EventDispatchThread.pumpEventsForFilter (EventDispatchThread.java:116)     at java.awt.EventDispatchThread.pumpEventsForHierarchy (EventDispatchThread.java:105)     at java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:101)     at java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:93)     at java.awt.EventDispatchThread.run (EventDispatchThread.java:82)

BUILT SUCCESSFUL (total time: 18 seconds)

I would like to know what I might have done wrong ... I already did exit tests with PrintLN and back characters, which means there is image saved in the bank!

    
asked by anonymous 27.11.2017 / 01:51

0 answers