Advertisement
Guest User

MySQL

a guest
Feb 23rd, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. package de.yodabosten.mysql;
  2.  
  3.  
  4.  
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9.  
  10. import org.bukkit.Bukkit;
  11.  
  12.  
  13.  
  14. import de.yodabosten.banmanager.Main;
  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.  
  26. public static void connect(){
  27. if(!isConnected()){
  28. System.out.println(" Port: " + port + " Host: " + host + " Username: " + username + " Password: " + password);
  29. try {
  30. con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
  31. Bukkit.getConsoleSender().sendMessage(Main.getInstance().prefix + "MySQL Verbingung aufgebaut!");
  32. }catch (SQLException e){
  33. e.printStackTrace();
  34. }
  35.  
  36.  
  37.  
  38.  
  39. }
  40. }
  41.  
  42. public static void close(){
  43. if(isConnected()){
  44. try {
  45. con.close();
  46. Bukkit.getConsoleSender().sendMessage(Main.getInstance().prefix + "MySQL Verbingung geschlossen !");
  47. } catch (SQLException e) {
  48. e.printStackTrace();
  49. }
  50.  
  51. }
  52.  
  53. }
  54.  
  55.  
  56.  
  57. public static boolean isConnected(){
  58. return con != null;
  59.  
  60. }
  61.  
  62.  
  63. public static void createTable(){
  64. /*
  65. *
  66. * Syntax: Spielername, UUID, Ende, Grund
  67. *
  68. */
  69.  
  70. if(isConnected()){
  71. try {
  72. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS BannedPlayers(Spielername VARCHAR(16), UUID VARCHAR(100), Ende VARCHAR(100), Grund VARCHAR(100))");
  73. } catch (SQLException e) {
  74. e.printStackTrace();
  75. }
  76.  
  77. }
  78.  
  79. }
  80.  
  81. public static void update(String qry){
  82. if(isConnected()){
  83. try {
  84. con.createStatement().executeUpdate(qry);
  85. } catch (SQLException e) {
  86. e.printStackTrace();
  87. }
  88. }
  89.  
  90.  
  91. }
  92.  
  93. public static ResultSet getResult(String qry){
  94. if(isConnected()){
  95. try {
  96. con.createStatement().executeQuery(qry);
  97. } catch (SQLException e) {
  98. e.printStackTrace();
  99. }
  100. }
  101. return null;
  102.  
  103.  
  104.  
  105. }
  106.  
  107.  
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement