RE:necesito ayuda con en imageicon
ASUMO QUE YA SABES ALGO DE CONEXIONES DEDE JAVA A BASE DE DATOS
si no lee JDBC
hola como estas primero que nada para meter a la base de datos esta uso esta pequeña clase para meter lo datos
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package blueserver.database;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.swing.JOptionPane;
/**
*
* @author Administrador
*/
public class Imagenes
{
public void insertarImagen(File imagen)
{
String INSERT_PICTURE = "INSERT INTO imagen VALUES (?,?, ?)";
PreparedStatement ps = null;
Conexion con = new Conexion();
con.conexionLocal();
try {
con.getConexionEstablecida().setAutoCommit(false);
FileInputStream fis = new FileInputStream(imagen);
ps = con.getConexionEstablecida().prepareStatement(INSERT_PICTURE);
ps.setString(1, "001");
ps.setString(1, imagen.getName());
ps.setBinaryStream(2, fis,(int) imagen.length());
ps.executeUpdate();
con.getConexionEstablecida().commit();
ps.close();
fis.close();
} catch (IOException ex) {
JOptionPane.showMessageDialog(null,"No se pudo cerra el flujo
" +
"Provocado por la clase
"+this.getClass().getName()
+"
Tipo de excepcion
"+ ex);
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null,"No se pudo insertar la Imagen
" +
"Provocado por la clase
"+this.getClass().getName()
+"
Tipo de excepcion
"+ ex);
}
}
}// fin de la clase imagenes
y no he echo la clase para leer pero tengo los metodos son los siguientes
ResultSet rs = stmt.executeQuery(”SELECT FOTO FROM IMAGEN WHERE ID = 001″);
byte[] img = rs.getBytes(”FOTO”);
como esta en binario lo convierets a tipo image y dir
private Image getImage(byte[] bytes, boolean isThumbnail) throws IOException {
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
Iterator readers = ImageIO.getImageReadersByFormatName(”jpeg”);
ImageReader reader = (ImageReader) readers.next();
Object source = bis; // File or InputStream
ImageInputStream iis = ImageIO.createImageInputStream(source);
reader.setInput(iis, true);
ImageReadParam param = reader.getDefaultReadParam();
if (isThumbnail) {
param.setSourceSubsampling(4, 4, 0, 0);
}
return reader.read(0, param);
}
y luego
Image imagen = getImage(img, false);
Icon icon = new ImageIcon(imagen);
btnBoton.setIcon(icon);
espero haberte sido de ayuda