Guest User

Untitled

a guest
Oct 24th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
  2. at crudvilcun.GUI.btnBuscarActionPerformed(GUI.java:111)
  3. at crudvilcun.GUI.access$000(GUI.java:12)
  4. at crudvilcun.GUI$1.actionPerformed(GUI.java:54)
  5.  
  6. package crudvilcun;
  7.  
  8. import com.mysql.jdbc.Connection;
  9. import com.mysql.jdbc.PreparedStatement;
  10. import java.sql.DriverManager;
  11. import java.sql.ResultSet;
  12. import java.sql.SQLException;
  13.  
  14. public class Metodos {
  15.  
  16. public static final String driver = "com.mysql.jdbc.Driver";
  17. public static final String url = "jdbc:mysql//localhost:3306/tienda";
  18. public static final String username = "root";
  19. public static final String password = "";
  20. Connection con = null;
  21. ResultSet rs = null;
  22. PreparedStatement ps = null;
  23. GUI contenido;
  24.  
  25. public Connection Conexion() {
  26.  
  27. try {
  28. Class.forName(driver);
  29. con = (Connection) DriverManager.getConnection(url, username, password);
  30.  
  31. } catch (ClassNotFoundException | SQLException e) {
  32. System.out.println("ERROR: " + e);
  33. }
  34.  
  35. return con;
  36. }
  37.  
  38. public void BuscarRegistro() {
  39.  
  40. try {
  41. con = Conexion();
  42. ps = (PreparedStatement) con.prepareStatement("SELECT * FROM personas (nombre,rut,dirección) where nombre=(?)");
  43. rs = ps.executeQuery();
  44.  
  45. if (rs.next()) {
  46. contenido.txtNombre.setText(rs.getString("nombre"));
  47. contenido.txtDireccion.setText(rs.getString("direccion"));
  48. contenido.txtRut.setText(rs.getString("rut"));
  49.  
  50. }
  51.  
  52. } catch (SQLException e) {
  53. System.out.println("ERROR: " + e);
  54. }
  55. }
  56.  
  57. }
Add Comment
Please, Sign In to add comment