Advertisement
Guest User

Untitled

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