Zo0PlayzHD

MinersNation.de | MySQL BanSystem | MySQL

Oct 1st, 2016
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. package me.lukas.ban;
  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 me.lukas.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 + "§aMySQL Verbindung aufgebaut!");
  26. } catch (SQLException e) {
  27. e.printStackTrace();
  28. }
  29. }
  30. }
  31.  
  32. public static void close() {
  33. if(isConnected()) {
  34. try {
  35. con.close();
  36. Bukkit.getConsoleSender().sendMessage(Main.getInstance().prefix + "§cMySQL Verbindung geschlossen!");
  37. } catch (SQLException e) {
  38. e.printStackTrace();
  39. }
  40.  
  41. }
  42. }
  43.  
  44. public static boolean isConnected() {
  45. return con != null;
  46. }
  47.  
  48. public static void createTable() {
  49. if(isConnected()) {
  50. try {
  51. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS BannedPlayers (Spielername VARCHAR(100), UUID VARCHAR(100), Ende VARCHAR(100), Grund VARCHAR(100))");
  52. } catch (SQLException e) {
  53. e.printStackTrace();
  54. }
  55. }
  56. }
  57.  
  58. public static void update(String qry) {
  59. if(isConnected()) {
  60. try {
  61. con.createStatement().executeUpdate(qry);
  62. } catch (SQLException e) {
  63. e.printStackTrace();
  64. }
  65. }
  66. }
  67.  
  68. public static ResultSet getResult(String qry) {
  69. if(isConnected()) {
  70. try {
  71. return con.createStatement().executeQuery(qry);
  72. } catch (SQLException e) {
  73. e.printStackTrace();
  74. }
  75. }
  76. return null;
  77. }
  78. }
Add Comment
Please, Sign In to add comment