Guest User

SQL

a guest
Jun 15th, 2018
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. package me.tixmcffa.Util;
  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. import java.sql.Statement;
  9. import org.bukkit.Bukkit;
  10. import org.bukkit.command.ConsoleCommandSender;
  11. import org.bukkit.configuration.file.FileConfiguration;
  12.  
  13. public class MySQL
  14. {
  15. public static Connection Con;
  16. public static String DataBase = FileManager.MySQLCfg.getString("MySQL.DataBase");
  17. public static String Host = FileManager.MySQLCfg.getString("MySQL.Host");
  18. public static String Password = FileManager.MySQLCfg.getString("MySQL.Password");
  19. public static int Port = FileManager.MySQLCfg.getInt("MySQL.Port");
  20. public static String User = FileManager.MySQLCfg.getString("MySQL.User");
  21.  
  22. public static boolean isConnected()
  23. {
  24. return Con != null;
  25. }
  26.  
  27. public static void Connect()
  28. {
  29. if (!isConnected()) {
  30. try
  31. {
  32. Con = DriverManager.getConnection("jdbc:mysql://" + Host + ":" + 3306 + "/" + DataBase, User, Password);
  33. Bukkit.getConsoleSender().sendMessage("�aMySQL connection established successfully.");
  34. }
  35. catch (SQLException e)
  36. {
  37. Bukkit.getConsoleSender().sendMessage("�cFailed to connect to the MySQL database.");
  38. }
  39. }
  40. }
  41.  
  42. public static void close()
  43. {
  44. if (isConnected()) {
  45. try
  46. {
  47. Con.close();
  48. Bukkit.getConsoleSender().sendMessage("�2MySQL connection closed succesfully!");
  49. }
  50. catch (SQLException e)
  51. {
  52. e.printStackTrace();
  53. }
  54. }
  55. }
  56.  
  57. public static void update(String qry)
  58. {
  59. if (isConnected()) {
  60. try
  61. {
  62. Con.prepareStatement(qry).executeUpdate();
  63. }
  64. catch (SQLException e)
  65. {
  66. e.printStackTrace();
  67. }
  68. }
  69. }
  70.  
  71. public static ResultSet getResult(String qry)
  72. {
  73. ResultSet resultSet = null;
  74. if (isConnected()) {
  75. try
  76. {
  77. resultSet = Con.prepareStatement(qry).executeQuery();
  78. }
  79. catch (SQLException e)
  80. {
  81. e.printStackTrace();
  82. }
  83. }
  84. return resultSet;
  85. }
  86.  
  87. public static void createTables()
  88. {
  89. if (isConnected()) {
  90. try
  91. {
  92. Con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS FFA (Playername VARCHAR(100), UUID VARCHAR(100), CurrentEffect int, LoveMove int, FireMove int, HappyArrow int, WitchArrow int, Rank int, Points int, Kills int, Deaths int)");
  93. }
  94. catch (SQLException e)
  95. {
  96. e.printStackTrace();
  97. }
  98. }
  99. }
  100. }
Add Comment
Please, Sign In to add comment