Guest User

Untitled

a guest
Sep 12th, 2016
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. package de.slixfx.slixpvp.util;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7.  
  8. import org.bukkit.Bukkit;
  9.  
  10. import de.slixfx.slixpvp.main.Main;
  11.  
  12. public class MySQL {
  13.  
  14. public static String username;
  15. public static String password;
  16. public static String database;
  17. public static String host;
  18. public static String port;
  19. public static Connection con;
  20.  
  21. public static void connect() {
  22. if(!isConnected()) {
  23. try {
  24. con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
  25. Bukkit.getConsoleSender().sendMessage(Main.getInstance().prefix + "MySQL Verbindung aufgebaut!");
  26. } catch (SQLException e) {
  27. Messager.MySQLConnectError();
  28. e.printStackTrace();
  29. }
  30. }
  31. }
  32.  
  33. public static void close() {
  34. if(isConnected()) {
  35. try {
  36. con.close();
  37. } catch (SQLException e) {
  38. Messager.MySQLDisconnectError();
  39. e.printStackTrace();
  40. }
  41. Bukkit.getConsoleSender().sendMessage(Main.getInstance().prefix + "MySQL Verbindung geschlossen!");
  42. }
  43. }
  44.  
  45. public static boolean isConnected() {
  46. return con != null;
  47. }
  48.  
  49. public static void createTables() {
  50. /**
  51. * Syntax: Spielername, UUID, Ende, Grund
  52. */
  53. if(isConnected()) {
  54. try {
  55. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS InArena (Spielername VARCHAR(100), UUID VARCHAR(100))");
  56. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS ArenaPoints (Punkt VARCHAR(100), X VARCHAR(100), Y VARCHAR(100), Z VARCHAR(100))");
  57. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS BannedPlayers (Spielername VARCHAR(100), UUID VARCHAR(100), Ende VARCHAR(100), Grund VARCHAR(100))");
  58. } catch (SQLException e) {
  59. e.printStackTrace();
  60. }
  61. }
  62. }
  63.  
  64. public static void update(String qry) {
  65. if(isConnected()) {
  66. try {
  67. con.createStatement().executeUpdate(qry);
  68. } catch (SQLException e) {
  69. Messager.MySQLError(qry);
  70. e.printStackTrace();
  71. }
  72. }
  73. }
  74.  
  75. public static ResultSet getResult(String qry) {
  76. if(isConnected()) {
  77. try {
  78. return con.createStatement().executeQuery(qry);
  79. } catch (SQLException e) {
  80. Messager.MySQLError(qry);
  81. e.printStackTrace();
  82. }
  83. }
  84. return null;
  85. }
  86.  
  87. }
Add Comment
Please, Sign In to add comment