Anda di halaman 1dari 3

void agregarImagen (){

JFileChooser archivo=new JFileChooser();


int ventana=archivo.showOpenDialog(null);
if(ventana==JFileChooser.APPROVE_OPTION){
File file=archivo.getSelectedFile();
jTextField1.setText(String.valueOf(file));
Image foto=getToolkit().getImage(jTextField1.getText());
LblFoto.setIcon(new ImageIcon(foto));
}
}

try{

String sql="UPDATE Paciente SET "

+"PacIdentificacion=?,"

+"PacNombre=?,"

+"PacApellidos=?,"

+"PacFechaNac=?,"

+"PacSexo=?,"

+"PacFoto=?,"

+"PacRuta=?"

+"WHERE idPaciente='"+txtidPaciente+"'";

PreparedStatement pps=cn.prepareStatement(sql);

pps.setString(1, txtIdentificacion.getText());

pps.setString(2, txtNombres.getText());
pps.setString(3, txtApellidos.getText());

pps.setString(4, Genero);

pps.setString(5,((JTextField)fechaNac.getDateEditor().getUiComponent()).getText());

FileInputStream archivoFoto;

archivoFoto=new FileInputStream(jTextField1.getText());

pps.setBinaryStream(6, archivoFoto);

pps.setString(7, jTextField1.getText());

pps.executeUpdate();

JOptionPane.showMessageDialog(null, "Los Datos del Paciente se han Actualizados");

mostrarPaciente();

}catch (SQLException ex){

Logger.getLogger(FrmRegPaciente.class.getName()).log(Level.SEVERE, null,ex);

} catch (FileNotFoundException ex) {

Logger.getLogger(FrmRegPaciente.class.getName()).log(Level.SEVERE, null, ex);

FileInputStream archivoFoto;

archivoFoto=new FileInputStream(jTextField1.getText());

pps.setBinaryStream(6, archivoFoto);

pps.setString(7, jTextField1.getText());
public static void main(String[] args) {

try{
File archivo = new File("C:\Users\David\Pictures\za.jpg");
byte[] imgFoto = new byte[(int)archivo.length()];
InputStream inte = new FileInputStream(archivo);
inte.read(imgFoto);

BufferedImage image = null;


InputStream in = new ByteArrayInputStream(imgFoto);
image = ImageIO.read(in);

ImageIcon icono = new ImageIcon(image);


JOptionPane.showMessageDialog(null, "Imagenes", "Imagen",
JOptionPane.INFORMATION_MESSAGE, icono);
}catch(Exception ex){
System.out.println(ex.getMessage());
}
}

Anda mungkin juga menyukai