Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. package nl.erbenvarvil.sql.test;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.event.Listener;
  6. import org.bukkit.plugin.java.JavaPlugin;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.SQLException;
  11.  
  12. /**
  13. * Gemaakt door Erben Varvil op 4-7-2017.
  14. */
  15. public class Main extends JavaPlugin implements Listener {
  16. private Connection connection;
  17. public String host, database, username, password, port;
  18.  
  19. public void onEnable() {
  20. mysqlSetup();
  21. }
  22.  
  23. public void mysqlSetup() {
  24. host = "shareddb1d.hosting.stackcp.net";
  25. username = "dyrhomc-3231e610";
  26. database = "dyrhomc-3231e610";
  27. port = "3306";
  28. password = "SQLDB123";
  29.  
  30.  
  31. try {
  32.  
  33.  
  34. synchronized (this) {
  35. if(getConnection() != null && !getConnection().isClosed()) {
  36. return;
  37. }
  38.  
  39. Class.forName("com.mysql.jdbc.Driver");
  40. setConnection(DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password));
  41.  
  42. Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "MYSQL CONNECTED");
  43. }
  44. } catch(SQLException e) {
  45. Bukkit.getServer().getConsoleSender().sendMessage("SQL Error at " + e.getMessage());
  46. } catch (ClassNotFoundException e){
  47. e.printStackTrace();
  48. }
  49. }
  50.  
  51.  
  52. public Connection getConnection() {
  53. return connection;
  54. }
  55.  
  56. public void setConnection(Connection connection) {
  57. this.connection = connection;
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement