Estou com um problema a um tempão, tenho uma imgem em um array de bytes comum até ae beleza, seto no banco, porem quando volta não mostra nada como se fosse inútil armazenar foto.
No Banco quando pesquisa fica assim: [B@430a540. Aqui é a parte legal do projeto que pega bem, onde eu vou inserir, com a variavel buffer:
FileNameExtensionFilter filtro = new FileNameExtensionFilter("*.jpg", "jpg");
chooser.setFileFilter(filtro);
int resposta = chooser.showOpenDialog(new JDialog());
File file = new File("");
if(resposta == JFileChooser.APPROVE_OPTION){
file = chooser.getSelectedFile();
String foto = file.getPath();
Foto.setText(foto);
textPane.insertIcon(new ImageIcon(Foto.getText()));
//ImageIcon image = new ImageIcon(Foto.getText());
byte[] buffer = new byte[(int) file.length()];
InputStream ios = null;
try {
ios = new FileInputStream(file);
if (ios.read(buffer) == -1) {
throw new IOException("EOF reached while trying to read the whole file");
}
if (ios != null){
ios.close();
}
}catch (IOException er) {
JOptionPane.showMessageDialog(null, "erro de buffer");
}
me.setFoto(buffer);
}else if(resposta == JFileChooser.CANCEL_OPTION){
}
Aqui eu criei uma outra classe para pegar a imagem do banco
byte[] cid = null;
try{
Statement stm = conn.createStatement();
ResultSet res = stm.executeQuery("select foto_mercado from mercado where idmercado = 21");
while (res.next()) {
cid=res.getBytes(1);
}
} catch (SQLException e1) {
JOptionPane.showMessageDialog(null, "erro foto");
// TODO Auto-generated catch block
e1.printStackTrace();
}
if(cid!=null){
InputStream input = new ByteArrayInputStream(cid);
try{
BufferedImage imagem = ImageIO.read(input);
JOptionPane.showMessageDialog(null, imagem);
textPane.insertIcon(new ImageIcon(imagem));
}catch(IOException ex){
JOptionPane.showMessageDialog(null, "erro");
}
}