Guest User

Untitled

a guest
Aug 5th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. private void jButton5ActionPerformed(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 id=this.jTextField9.getText();
  17. Statement s=conectar.createStatement();
  18. ResultSet rs=s.executeQuery("SELECT id,Nombre,Apellido,Email,Telefono,Compañia,Posicion,Foto,Ruta,Nota FROM datos WHERE id='"+id+"'");
  19. if(rs.next()){
  20. jTextField1.setText(rs.getString(1));
  21. jTextField2.setText(rs.getString(2));
  22. jTextField3.setText(rs.getString(3));
  23. jTextField4.setText(rs.getString(4));
  24. jTextField5.setText(rs.getString(5));
  25. jTextField6.setText(rs.getString(6));
  26. jTextField7.setText(rs.getString(7));
  27. jTextField8.setText(rs.getString(8));
  28.  
  29. Image i=null;
  30. Blob blob=rs.getBlob("Foto");
  31. i=javax.imageio.ImageIO.read(blob.getBinaryStream());
  32. ImageIcon image=new ImageIcon(i);
  33. jLabel10.setIcon(image);
  34. jTextField10.setText(rs.getString(10));
  35.  
  36.  
  37. }
  38. else{
  39. JOptionPane.showMessageDialog(null,"El contacto" +id+ "no se encuentra");
  40. }
  41. } catch (SQLException ex) {
  42. Logger.getLogger(datos.class.getName()).log(Level.SEVERE, null, ex);
  43. } catch (IOException ex) {
  44. Logger.getLogger(datos.class.getName()).log(Level.SEVERE, null, ex);
  45. }
  46. }
Add Comment
Please, Sign In to add comment