Advertisement
Guest User

Untitled

a guest
Nov 6th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. package net.Syntaxfehler.gungame.mysql;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.command.ConsoleCommandSender;
  8.  
  9. public class MySQL
  10. {
  11. public static String host;
  12. public static String port;
  13. public static String database;
  14. public static String username;
  15. public static String password;
  16. public static Connection con;
  17.  
  18. public static void connect()
  19. {
  20. if (!isConnected()) {
  21. try
  22. {
  23. con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
  24. Bukkit.getConsoleSender().sendMessage("§8[§6MySQL§8] §3Verbindung zur MySQL-Datenbank wurde herrgestellt§8.");
  25. }
  26. catch (SQLException e)
  27. {
  28. e.printStackTrace();
  29. }
  30. }
  31. }
  32.  
  33. public static void disconnect()
  34. {
  35. if (isConnected()) {
  36. try
  37. {
  38. con.close();
  39. Bukkit.getConsoleSender().sendMessage("§8[§6MySQL§8] §3Verbindung zur MySQL-Datenbank wurde getrennt§8.");
  40. }
  41. catch (SQLException e)
  42. {
  43. e.printStackTrace();
  44. }
  45. }
  46. }
  47.  
  48. public static boolean isConnected()
  49. {
  50. return con != null;
  51. }
  52.  
  53. public static Connection getConnection()
  54. {
  55. return con;
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement