Advertisement
Guest User

Untitled

a guest
Aug 5th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. package de.byfoxy.main.manager;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.SQLException;
  7.  
  8. import de.byfoxy.main.Main;
  9.  
  10. public class MySQL {
  11.  
  12. private static String host = Main.instance.getConfig().getString("MySQL.host");
  13. private static String port = Main.instance.getConfig().getString("MySQL.port");
  14. private static String user = Main.instance.getConfig().getString("MySQL.user");
  15. private static String passwort = Main.instance.getConfig().getString("MySQL.password");
  16. private static String database = Main.instance.getConfig().getString("MySQL.database");
  17. public static Connection con;
  18.  
  19. public static void connect() {
  20. if (!connected()) {
  21. try {
  22. con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true", user, passwort);
  23. System.out.println("[ScoreKill] Die MySQL Verbindung wurde aufgebaut.");
  24. createTable();
  25. } catch (SQLException e) {
  26. System.out.println("[ScoreKill] Kein Verbindung zum MySQL Server gefunden! ERROR CODE: #1612");
  27. }
  28. }
  29. }
  30.  
  31. private static void createTable() {
  32. if (connected()) {
  33. PreparedStatement ps = MySQL.getStatement("CREATE TABLE IF NOT EXISTS KillManager (UUID VARCHAR(64), Kills int)");
  34. try {
  35. ps.executeUpdate();
  36. } catch (SQLException e) {
  37. e.printStackTrace();
  38. }
  39. }
  40.  
  41. }
  42.  
  43. public static PreparedStatement getStatement(String sql) {
  44. if (connected()) {
  45. try {
  46. return con.prepareStatement(sql);
  47. } catch (SQLException e) {
  48. e.printStackTrace();
  49. }
  50. }
  51. return null;
  52. }
  53.  
  54. public static boolean connected() {
  55. return con != null;
  56. }
  57.  
  58. public static void disconnect() {
  59. if (connected()) {
  60. try {
  61. con.close();
  62. System.out.println("[ScoreKill] Die MySQL Verbindung wurde geschlossen.");
  63. } catch (SQLException e) {
  64. e.printStackTrace();
  65. }
  66. }
  67. }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement