Advertisement
Guest User

Untitled

a guest
Nov 9th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. package de.slixfx.slixstats.utils;
  2.  
  3. import de.slixfx.slixstats.main.Main;
  4.  
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.util.Arrays;
  10.  
  11. /**
  12. * Created by SlixFX on 11.07.2017 with Heart <3.
  13. */
  14. public class MySQL {
  15.  
  16. public static String username;
  17. public static String password;
  18. public static String database;
  19. public static String host;
  20. public static String port;
  21. public static Connection con;
  22.  
  23. public static void connect() {
  24. if(!isConnected()) {
  25. try {
  26. con = DriverManager.getConnection("jdbc:mysql://" + host + ":"+port+"/" + database, username, password);
  27. System.out.println(Main.getInstance().prefix + "MySQL Verbindung aufgebaut!");
  28. } catch (SQLException e) {
  29. e.printStackTrace();
  30. }
  31. }
  32. }
  33.  
  34. public static void close() {
  35. if(isConnected()) {
  36. try {
  37. con.close();
  38. } catch (SQLException e) {
  39. e.printStackTrace();
  40. }
  41. System.out.println(Main.prefix + "§aMySQL Verbindung geschlossen!");
  42. }
  43. }
  44.  
  45. public static boolean isConnected() {
  46. return con != null;
  47. }
  48.  
  49. public static void createTables() {
  50. if(!isConnected()) {
  51. System.out.println(Main.prefix+"§cMySQL-Verbindung besteht nicht, versuche neu zu verbinden");
  52. connect();
  53. }
  54. try {
  55. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS connections (Name VARCHAR(60), UUID VARCHAR(36), IP INT UNSIGNED, Server VARCHAR(100), Unixtime BIGINT, Date VARCHAR(22), Playerstate TINYINT(1), Type TINYINT(1))");
  56. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS onlineplayers (Name VARCHAR(60), UUID VARCHAR(36), Server VARCHAR(100), Playerstate TINYINT(1))");
  57. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS commands (Name VARCHAR(60), UUID VARCHAR(36), IP INT USIGNED, Server VARCHAR(100), Command VARCHAR(100), Permission VARCHAR(100), Server VARCHAR(100), World VARCHAR(40), X INT, Y INT, Z INT, Playerstate TINYINT(1), OP TINYINT(1), Unixtime BIGINT, Date VARCHAR(22))");
  58. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS playtime (Name VARCHAR(60), UUID VARCHAR(36), Server VARCHAR(100), Playtime BIGINT UNSIGNED, Afktime BIGINT UNSIGNED)");
  59. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS chat (Name VARCHAR(60), UUID VARCHAR(36), Server VARCHAR(100), World VARCHAR(40), X INT, Y INT, Z INT , Message VARCHAR(100), Unixtime BIGINT, Date VARCHAR(22), Playerstate TINYINT(1))");
  60. } catch (SQLException e) {
  61. e.printStackTrace();
  62. }
  63. }
  64.  
  65. public static void update(String qry) {
  66. if(!isConnected()) {
  67. System.out.println(Main.prefix+"§cMySQL-Verbindung besteht nicht, versuche neu zu verbinden");
  68. connect();
  69. return;
  70. }
  71. try {
  72. con.createStatement().executeUpdate(qry);
  73. } catch (SQLException e) {
  74. e.printStackTrace();
  75. }
  76. }
  77.  
  78. public static ResultSet getResult(String qry) {
  79. if(!isConnected()) {
  80. System.out.println(Main.prefix+"§cMySQL-Verbindung besteht nicht, versuche neu zu verbinden");
  81. connect();
  82. }
  83. try {
  84. return con.createStatement().executeQuery(qry);
  85. } catch (SQLException e) {
  86. e.printStackTrace();
  87. }
  88. return null;
  89. }
  90.  
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement