Guest User

Untitled

a guest
Aug 5th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
  2. Connection conectar = null;
  3.  
  4. try{
  5.  
  6. Class.forName("com.mysql.jdbc.Driver");
  7. conectar = (Connection) DriverManager.getConnection("jdbc:mysql://127.0.0.1/proyecto", "root", "");
  8.  
  9.  
  10. } catch (ClassNotFoundException ex) {
  11. Logger.getLogger(datos.class.getName()).log(Level.SEVERE, null, ex);
  12. } catch (SQLException ex) {
  13. Logger.getLogger(datos.class.getName()).log(Level.SEVERE, null, ex);
  14. }
  15. try{
  16. String sql= "UPDATE datos SET Nombre=?,"+ "Apellido=?,"+ "Email=?,"+"Foto=?,"+"Ruta=?,"+"Posicion=?,"+"Compañia=?,"+"Nota=?,"+"Telefono=?" +"WHERE Nombre='"+jTextField1.getText()+"'";
  17.  
  18. PreparedStatement pst= conectar.prepareStatement(sql);
  19.  
  20. pst.setString(1, jTextField1.getText());
  21. pst.setString(2, jTextField2.getText());
  22. pst.setString(3, jTextField3.getText());
  23. pst.setString(4, jTextField4.getText());
  24. pst.setString(5, jTextField5.getText());
  25. pst.setString(6, jTextField6.getText());
  26. pst.setString(7, jTextField8.getText());
  27. FileInputStream ArchivosFoto;
  28. FileInputStream Archivofoto = new FileInputStream(jTextField7.getText());
  29. pst.setBinaryStream(8, Archivofoto);
  30. pst.setString(9, jTextField7.getText());
  31. int n = pst.executeUpdate();
  32. if (n > 0) {
  33. JOptionPane.showMessageDialog(null, "Se modificaron los datos de manera correcta :D");
  34. tablaDatos();
  35.  
  36. } else {
  37.  
  38. JOptionPane.showMessageDialog(null, "Ocurrio un error, no se pudo modificar los datos :c");
  39.  
  40. }
  41. } catch (SQLException ex) {
  42. Logger.getLogger(datos.class.getName()).log(Level.SEVERE, null, ex);
  43. } catch (FileNotFoundException ex) {
  44. Logger.getLogger(datos.class.getName()).log(Level.SEVERE, null, ex);
  45. }
  46. }
Add Comment
Please, Sign In to add comment