Advertisement
Guest User

Untitled

a guest
Apr 16th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1.  
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.SQLException;
  5.  
  6. public class Conexion {
  7.  
  8. private static Conexion conexion;
  9. private Connection conection;
  10.  
  11. private Conexion(String base, String user, String pass) {
  12. this.conection = conectar(base, user, pass);
  13. }
  14.  
  15. private Connection conectar(String base, String user, String pass) {
  16. Connection connct = null;
  17. try {
  18. connct = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/" + base + "?useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC", user, pass);
  19. } catch (SQLException e) {
  20. // TODO Auto-generated catch block
  21. e.printStackTrace();
  22. }
  23.  
  24. return connct;
  25. }
  26.  
  27. public static Conexion getInstance() {
  28. if (conexion == null) {
  29. conexion = new Conexion("m_examenProg", "m", "1234");
  30. }
  31. return conexion;
  32. }
  33.  
  34. public Connection getConection() {
  35. return conection;
  36. }
  37.  
  38. public void setConection(Connection conection) {
  39. this.conection = conection;
  40. }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement