Advertisement
Guest User

Untitled

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