Advertisement
Guest User

Untitled

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