Guest User

Untitled

a guest
Apr 22nd, 2019
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. package ru.nestway.mysql;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class MySQL
  8. extends Database
  9. {
  10. private final String user;
  11. private final String database;
  12. private final String password;
  13. private final String port;
  14. private final String hostname;
  15.  
  16. public MySQL(String hostname, String port, String database, String username, String password)
  17. {
  18. this.hostname = hostname;
  19. this.port = port;
  20. this.database = database;
  21. this.user = username;
  22. this.password = password;
  23. }
  24.  
  25. public Connection openConnection()
  26. throws SQLException, ClassNotFoundException
  27. {
  28. if (checkConnection()) {
  29. return this.connection;
  30. }
  31. Class.forName("com.mysql.jdbc.Driver");
  32. this.connection = DriverManager.getConnection("jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database + "?autoReconnect=true", this.user, this.password);
  33.  
  34. return this.connection;
  35. }
  36. }
Add Comment
Please, Sign In to add comment