Guest User

Untitled

a guest
Feb 15th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. /*
  2. * Creado por: David Pérez S.
  3. * Universidad Politécnica de Chiapas
  4. * Fecha de Creación: 12/11/2018
  5. */
  6.  
  7. import java.sql.Connection;
  8. import java.sql.DriverManager;
  9. import java.sql.SQLException;
  10.  
  11. /**
  12. * @author David Pérez S.
  13. */
  14. public class ConexionSQL {
  15.  
  16. private final String nombreServidor;
  17. private final String numeroPuerto;
  18. private final String nombreBD;
  19. private final String nombreUsuario;
  20. private final String contraseñaUsuario;
  21.  
  22. public ConexionSQL() {
  23. this.nombreServidor = "Nombre de tu servidor";
  24. this.numeroPuerto = "1433"; // Este es el puerto por defecto, a menos que lo hayas cambiado
  25. this.nombreBD = "Nombre de tu BD";
  26. this.nombreUsuario = "Tu nombre de usuario";
  27. this.contraseñaUsuario = "Tu contraseña";
  28. }
  29.  
  30. public Connection conectar() {
  31. String connectionUrl = "jdbc:sqlserver://" + nombreServidor + ":" + numeroPuerto + ";" + nombreBD + "=AdventureWorks;user=" + nombreUsuario + ";password=" + contraseñaUsuario;
  32. try {
  33. Connection connection = DriverManager.getConnection(connectionUrl);
  34. return connection;
  35. } // Handle any errors that may have occurred.
  36. catch (SQLException e) {
  37. System.err.println(e);
  38. return null;
  39. }
  40. }
  41. }
Add Comment
Please, Sign In to add comment