Advertisement
SatproMC

Untitled

Oct 27th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. package triplx.lobby.hub.mysql;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5.  
  6. import java.sql.Connection;
  7. import java.sql.DriverManager;
  8. import java.sql.SQLException;
  9.  
  10. public class SQLManager {
  11.  
  12.     public String host, database, username, password, table;
  13.     public int port;
  14.  
  15.     public static SQLManager getInstance(){
  16.         return new SQLManager();
  17.     }
  18.  
  19.     private Connection connection;
  20.  
  21.  
  22.  
  23.     public void setupMySQL(){
  24.         host = "host";
  25.         port = 3306;
  26.         database = "**";
  27.         username = "**";
  28.         password = "**";
  29.         table = "player_lobby_settings";
  30.  
  31.         try {
  32.             synchronized (this){
  33.                 if (getConnection() != null && !getConnection().isClosed()){
  34.                     return;
  35.                 }
  36.                 Class.forName("com.mysql.jdbc.Driver");
  37.                 setConnection(DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password));
  38.                 Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "MySQL Connected!");
  39.             }
  40.         } catch (SQLException | ClassNotFoundException e){
  41.             e.printStackTrace();
  42.         }
  43.  
  44.     }
  45.  
  46.     public Connection getConnection() {
  47.         return connection;
  48.     }
  49.  
  50.     private void setConnection(Connection connection){
  51.         this.connection = connection;
  52.     }
  53.  
  54.  
  55.  
  56.  
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement