Advertisement
Guest User

Untitled

a guest
Oct 11th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. package de.GamingWolves.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 org.bukkit.Bukkit;
  10. import org.bukkit.entity.Player;
  11.  
  12. import de.GamingWolves.Lobby.Main;
  13. import net.md_5.bungee.api.ChatColor;
  14.  
  15.  
  16. public class MySQL {
  17.  
  18. public static String host ="127.0.0.1";
  19. public static String port ="3306";
  20. public static String datebase = "lobby";
  21. public static String username = "root";
  22. public static String password = "";
  23. public static Connection con;
  24.  
  25.  
  26. public static void connect(){
  27. if(!isConnected()){
  28. try {
  29. con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + datebase,username,password);
  30. Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "[MySQL] Verbindung aufgebaut!");
  31. } catch (SQLException e) {
  32. e.printStackTrace();
  33. }
  34. }
  35. }
  36.  
  37.  
  38. public static void disConnect(){
  39. if(isConnected()){
  40. try {
  41. con.close();
  42. Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[MySQL] Verbindung geschlossen!");
  43. } catch (SQLException e) {
  44. e.printStackTrace();
  45. }
  46. }
  47. }
  48.  
  49. public static boolean isConnected(){
  50. return(con == null ? false : true);
  51. }
  52.  
  53.  
  54.  
  55. public static Connection getConnection(){
  56. return con;
  57. }
  58.  
  59. public static void checkMySQLConnection(Player p){
  60. String state = null;
  61.  
  62. if(con == null){
  63. state = "§cnicht verbunden";
  64. }else if(con != null){
  65. state = "§averbunden";
  66. }
  67. if(p instanceof Player){
  68. p.sendMessage(Main.prefix + ChatColor.GOLD + "Der Aktuelle MySQL Status: " + state);
  69. }else{
  70. Bukkit.getConsoleSender().sendMessage(Main.prefix + ChatColor.GOLD + "Der Aktuelle MySQL Status: " + state);
  71.  
  72. }
  73.  
  74. }
  75.  
  76.  
  77.  
  78. public static boolean isUserInDatabase(String uuid){
  79. try{
  80. PreparedStatement ps = con.prepareStatement("SELECT * FROM `hideplayer` WHERE UUID = ?");
  81. ps.setString(1, uuid);
  82. ResultSet rs = ps.executeQuery();
  83. return rs.next();
  84. }
  85. catch (SQLException e) {
  86. e.printStackTrace();
  87. }
  88. return false;
  89. }
  90.  
  91. public static boolean isWarpNameInDatabase(String WarpName){
  92. try{
  93. PreparedStatement ps = con.prepareStatement("SELECT * FROM `warps` WHERE Name = ?");
  94. ps.setString(1, WarpName);
  95. ResultSet rs = ps.executeQuery();
  96. return rs.next();
  97. }
  98. catch (SQLException e) {
  99. e.printStackTrace();
  100. }
  101. return false;
  102. }
  103. public static boolean isUserWithBootsinDatabase(String uuid){
  104.  
  105. try{
  106. PreparedStatement ps = con.prepareStatement("SELECT * FROM `boots` WHERE UUID = ?");
  107. ps.setString(1, uuid);
  108. ps.execute();
  109. }catch (SQLException e) {
  110.  
  111. }
  112.  
  113. return false;
  114.  
  115. }
  116. public static boolean isUserInDatabase_Boots0(String uuid, String Boots){
  117.  
  118. try{
  119. PreparedStatement ps = con.prepareStatement("SELECT * FROM ");
  120. ps.setString(1, uuid);
  121. ps.setString(2, Boots);
  122. }catch (SQLException e) {
  123.  
  124. }
  125.  
  126. return false;
  127.  
  128. }
  129.  
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement