Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Creo la conexión
- static Connection connection = null;
- Class.forName("com.mysql.jdbc.Driver");
- connection =DriverManager.getConnection( "jdbc:mysql://midominio.org:3306/nombreDB", "usuario", "contraseña");
- JFileChooser chooser = new JFileChooser();
- FileFilter imageFilter = new FileNameExtensionFilter("Imágenes", ImageIO.getReaderFileSuffixes());
- chooser.setFileFilter(imageFilter);
- chooser.showOpenDialog(null);
- File file = chooser.getSelectedFile();
- if(file != null)
- {
- BufferedImage img;
- FileInputStream fis = null;
- try {
- img=ImageIO.read(file);
- Image img2 = img.getScaledInstance(50, 67, 50);
- ImageIcon icon=new ImageIcon(img2);
- fotoLb.setIcon(icon);
- fotoLb.revalidate();
- fotoLb.repaint();
- fis = new FileInputStream(file);
- String sentencia = "UPDATE persona SET FOTOGRAFIA = ? WHERE id_persona = ?";
- PreparedStatement pst;
- try {
- pst = connection.prepareStatement(sentencia);
- pst.setBinaryStream(1, fis, (int) file.length());
- pst.setInt(2,idPersona);
- pst.executeUpdate();
- pst.close();
- } catch (SQLException | IOException ex) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement