Guest User

Untitled

a guest
Jan 13th, 2016
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. package de.grani.bansystem.mysql;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7.  
  8.  
  9. import org.bukkit.Bukkit;
  10.  
  11. import de.grani.bansystem.main.Main;
  12.  
  13. /**
  14. * Created by Grani on 3.1.2016
  15. */
  16. public class MySQL {
  17.  
  18. public static String username;
  19. public static String password;
  20. public static String database;
  21. public static String host;
  22. public static String port;
  23. public static Connection con;
  24.  
  25. public static void connect() {
  26. if(!isConnected()) {
  27. try {
  28. con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port +"/" + database, username, password);
  29. Bukkit.getConsoleSender().sendMessage(Main.getInstance().prefix + "MySQL verbindunng aufgebaut!");
  30. } catch (SQLException e) {
  31. e.printStackTrace();
  32. }
  33. }
  34. }
  35.  
  36. public static void close() {
  37. if(isConnected()) {
  38. try {
  39. con.close();
  40. Bukkit.getConsoleSender().sendMessage(Main.getInstance().prefix + "MySQL verbindunng geschlossen!");
  41. } catch (SQLException e) {
  42. e.printStackTrace();
  43. }
  44. }
  45. }
  46.  
  47. public static boolean isConnected() {
  48. return con != null;
  49. }
  50.  
  51. public static void createTable() {
  52. /*
  53. *
  54. * Syntax: Spielername, UUID, Ende, Grund
  55. *
  56. */
  57. if(isConnected()) {
  58. try {
  59. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS BannedPlayers (Spielername VARCHAR(100), UUID VARCHAR(100), Ende VARCHAR(100), Grund VARCHAR(100))");
  60. } catch (SQLException e) {
  61. e.printStackTrace();
  62. }
  63. }
  64. }
  65.  
  66. public static void update(String qry) {
  67. if(isConnected()) {
  68. try {
  69. con.createStatement().executeUpdate(qry);
  70. } catch (SQLException e) {
  71. e.printStackTrace();
  72. }
  73. }
  74. }
  75.  
  76. public static ResultSet getResult(String qry) {
  77. if(isConnected()) {
  78. try {
  79. return con.createStatement().executeQuery(qry);
  80. } catch (SQLException e) {
  81. e.printStackTrace();
  82. }
  83. }
  84. return null;
  85. }
  86.  
  87. }
Add Comment
Please, Sign In to add comment