Advertisement
Guest User

BungeeBanSystem - MySQL

a guest
Sep 2nd, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. package de.betacoding.bansystem.mysql;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8.  
  9. import net.md_5.bungee.api.ProxyServer;
  10.  
  11. public class MySQL {
  12.  
  13. public static String host = "localhost";
  14. public static String password = "abc";
  15. public static String port = "3306";
  16. public static String username = "localhost";
  17. public static String database = "System";
  18.  
  19. public static Connection con;
  20.  
  21. public static Connection getConnection() {
  22. return con;
  23. }
  24.  
  25. public static boolean isConnected() {
  26. return con != null;
  27. }
  28.  
  29. @SuppressWarnings("deprecation")
  30. public static void connect() {
  31. if(!isConnected()) {
  32. try{
  33. con = DriverManager.getConnection("jdbc:mysql://"+host+":"+port+"/"+database+username+password);
  34. ProxyServer.getInstance().getConsole().sendMessage("§5[MySQL] §4Verbindung wurde aufgebaut.");
  35. }catch(SQLException ex) {
  36. ProxyServer.getInstance().getConsole().sendMessage("§5[MySQL] §4Verbindung konnte nicht aufgebaut werden.");
  37. }
  38. }
  39. }
  40.  
  41. @SuppressWarnings("deprecation")
  42. public static void disconnect() {
  43. if(isConnected()) {
  44. try{
  45. con.close();
  46. ProxyServer.getInstance().getConsole().sendMessage("§5[MySQL] §4Verbindung wurde aufgebaut.");
  47. }catch(SQLException ex) {
  48. ProxyServer.getInstance().getConsole().sendMessage("§5[MySQL] §4Verbindung konnte nicht aufgebaut werden.");
  49. }
  50. }
  51. }
  52.  
  53. public static void createTable() {
  54. if(isConnected()) {
  55. try{
  56. PreparedStatement ps = getConnection().prepareStatement("CREATE TABLE IF NOT EXISTS BanPlugin (Spielername VARCHAR(100), UUID VARCHAR(100), Ende VARCHAR(100), Grund VARCHAR(200))");
  57. ps.executeUpdate();
  58. ps.close();
  59. }catch(SQLException ex) {
  60. ex.printStackTrace();
  61. }
  62. }
  63. }
  64.  
  65. public static boolean isPlayerExisting(String uuid) {
  66. try{
  67. PreparedStatement ps = getConnection().prepareStatement("SELECT * FROM BanPlugin WHERE UUID = '"+uuid+"'");
  68. ps.executeUpdate();
  69. ResultSet rs = ps.executeQuery();
  70. boolean exists = rs.next();
  71. rs.close();
  72. ps.close();
  73. return exists;
  74. }catch(SQLException ex) {
  75. ex.printStackTrace();
  76. }
  77. return false;
  78. }
  79.  
  80. public static void addPlayer(String name, String uuid, long end, String reason) {
  81. try{
  82. PreparedStatement ps = getConnection().prepareStatement("INSERT INTO BanPlugin (Spielername, UUID, Ende, Grund) VALUES ('"+name+"', '"+uuid+"', '"+end+"', '"+reason+"')");
  83. ps.execute();
  84. ps.close();
  85. }catch(SQLException ex) {
  86. ex.printStackTrace();
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement