Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. package roleplay.mysql;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.ChatColor;
  9. import org.bukkit.plugin.Plugin;
  10.  
  11. import roleplay.main.Main;
  12.  
  13. public class MysqlConnect {
  14.  
  15. private Connection connection;
  16. public String host, data, database, username, password, table;
  17. public int port;
  18. Plugin plugin = Main.getPlugin(Main.class);
  19.  
  20.  
  21. public void mysqlSetup() {
  22. host = plugin.getConfig().getString("host");
  23. port = plugin.getConfig().getInt("port");
  24. database = plugin.getConfig().getString("database");
  25. username = plugin.getConfig().getString("username");
  26. password = plugin.getConfig().getString("password");
  27. table = plugin.getConfig().getString("table");;
  28.  
  29. try {
  30.  
  31. synchronized (this) {
  32. if (getConnection() != null && !getConnection().isClosed()) {
  33.  
  34. return;
  35. }
  36.  
  37. Class.forName("com.mysql.jdbc.Driver");
  38. setConnection(
  39. DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database,
  40. this.username, this.password));
  41.  
  42. Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "[Roleplay] MYSQL connected!");
  43.  
  44. }
  45. } catch (SQLException e) {
  46. e.printStackTrace();
  47.  
  48. } catch (ClassNotFoundException e) {
  49.  
  50. e.printStackTrace();
  51.  
  52. }
  53.  
  54. }
  55.  
  56. public Connection getConnection() {
  57. return connection;
  58.  
  59. }
  60.  
  61. public void setConnection(Connection connection) {
  62.  
  63. this.connection = connection;
  64.  
  65. }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement