Guest User

Untitled

a guest
Jul 16th, 2017
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. public class MySQL {
  2.  
  3.  
  4. public static String username;
  5. public static String password;
  6. public static String database;
  7. public static String host;
  8. public static String port;
  9. public static Connection con;
  10.  
  11.  
  12.  
  13. public static void connect() {
  14.  
  15. if(!isConnected()) {
  16. try {
  17. con = DriverManager.getConnection("jdbc:mysql://"+ host + ":3306/" + database, username, password);
  18. } catch (SQLException e) {
  19. e.printStackTrace();
  20. System.out.println("[FEHLER]: " + e.getMessage());
  21. }
  22. }
  23. }
  24.  
  25. public static void close() {
  26. if(isConnected()) {
  27. try {
  28. con.close();
  29. Bukkit.getConsoleSender().sendMessage(Main.getInstance().prefix+"MySQL Verbindung verloren oder unterbrochen!");
  30. } catch (SQLException e) {
  31. e.printStackTrace();
  32. System.out.println("[FEHLER]: " + e.getMessage());
  33. }
  34.  
  35. }
  36. }
  37.  
  38. public static boolean isConnected() {
  39. return con != null;
  40. }
  41.  
  42.  
  43. public static void createTable() {
  44. /*
  45. *
  46. * Syntax: Spielername, UUID, Ende, Grund
  47. *
  48. */
  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. System.out.println("[FEHLER]: " + e.getMessage());
  55. }
  56. }
  57. }
  58.  
  59.  
  60. public static void update(String qry) {
  61. if(isConnected()) {
  62. try {
  63. con.createStatement().executeUpdate(qry);
  64. } catch (SQLException e) {
  65. e.printStackTrace();
  66. System.out.println("[FEHLER]: " + e.getMessage());
  67. }
  68. }
  69. }
  70.  
  71. public static ResultSet getResult(String qry) {
  72. if(isConnected()) {
  73. try {
  74. return con.createStatement().executeQuery(qry);
  75. } catch (SQLException e) {
  76. e.printStackTrace();
  77. System.out.println("[FEHLER]: " + e.getMessage());
  78. }
  79. }
  80. return null;
  81. }
  82. }
Add Comment
Please, Sign In to add comment