Guest User

Untitled

a guest
Jan 2nd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. /*
  2. * ---------------------------------------
  3. * Copyright @RoyalByte | Adrian Schiel
  4. * Youtube : RoyalByte Developer
  5. * Skype: RoyalByte
  6. * Website: RoyalByte.net
  7. * ---------------------------------------
  8. */
  9.  
  10. package net.royalbyte.cores.mysql;
  11.  
  12.  
  13. import java.sql.Connection;
  14. import java.sql.DriverManager;
  15. import java.sql.ResultSet;
  16. import java.sql.SQLException;
  17. import java.sql.Statement;
  18.  
  19.  
  20. public class MySQL {
  21.  
  22. public static String host;
  23. public static String username;
  24. public static String database;
  25. public static String password;
  26. public static int port;
  27. public static Connection con;
  28.  
  29. public static boolean aktiv;
  30.  
  31. public static String getMySQLEnabledMSG() {
  32. if(aktiv) {
  33. return "§aAktiviert";
  34. }else {
  35. return "§cDeaktiviert";
  36. }
  37. }
  38.  
  39. public static void connect() {
  40. if (!isConnected()) {
  41. try {
  42. con = DriverManager.getConnection(
  43. "jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true", username,
  44. password);
  45.  
  46. System.out.println("Die §2MySQL §awurde verbunden.");
  47. } catch (SQLException e) {
  48. System.out.println("Konnte §4MySQL §cnicht verbinden.");
  49. }
  50. }
  51. }
  52.  
  53. public static void close() {
  54. if (isConnected()) {
  55. try {
  56. con.close();
  57. System.out.println("Die §2MySQL §awurde geschlossen.");
  58.  
  59. } catch (SQLException e) {
  60. System.out.println("Konnte §4MySQL §cnicht beenden.");
  61. }
  62.  
  63. }
  64.  
  65. }
  66.  
  67. public static boolean isConnected() {
  68. return con != null;
  69. }
  70.  
  71.  
  72. public static void update(String qry)
  73. {
  74. try
  75. {
  76. Statement st = con.createStatement();
  77. st.executeUpdate(qry);
  78. st.close();
  79. }
  80. catch (SQLException e)
  81. {
  82. connect();
  83. System.err.println(e);
  84. }
  85. }
  86.  
  87.  
  88. public static ResultSet getResult(String qry) {
  89. ResultSet rs = null;
  90. try
  91. {
  92. Statement st = con.createStatement();
  93. rs = st.executeQuery(qry);
  94. }
  95. catch (SQLException e)
  96. {
  97. connect();
  98. System.err.println(e);
  99. }
  100. return rs;
  101. }
  102.  
  103.  
  104. public static void createTable() {
  105. update("CREATE TABLE IF NOT EXISTS Stats (Name VARCHAR(16), UUID VARCHAR(100), points INT(100), wins INT(100) , loses INT(100), played_games INT(100), kills INT(100), deaths INT(100), beacons INT(100));");
  106. }
  107.  
  108.  
  109. }
Add Comment
Please, Sign In to add comment