Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. package me.trollc.swampessentials.utils;
  2.  
  3. import java.sql.DriverManager;
  4. import java.sql.SQLException;
  5.  
  6. import com.mysql.jdbc.Connection;
  7.  
  8. import me.trollc.swampessentials.Main;
  9.  
  10. public class SQL {
  11. private Connection connection;
  12. private Main pl;
  13. public SQL(Main plugin) {
  14. this.pl = plugin;
  15. }
  16. public void openConnection() throws SQLException, ClassNotFoundException {
  17. if (this.connection != null && !this.connection.isClosed()) {
  18. return;
  19. }
  20. synchronized (this) {
  21. if (this.connection != null && !this.connection.isClosed()) {
  22. return;
  23. }
  24. Class.forName("com.mysql.jdbc.Driver");
  25. this.connection = (Connection) DriverManager.getConnection("jdbc:mysql://" + this.pl.getConfig().getString("mysql.host") + ":" + this.pl.getConfig().getInt("mysql.port") + "/" + this.pl.getConfig().getString("mysql.db"), this.pl.getConfig().getString("mysql.user"), this.pl.getConfig().getString("mysql.pass"));
  26. }
  27. }
  28.  
  29. public Connection getConnection() {
  30. return this.connection;
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement