Advertisement
Guest User

MySQL

a guest
Mar 24th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. MySQL:
  2.  
  3. package ch.fluq.banmanager.mysql;
  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. import ch.fluq.banmanager.Main;
  13.  
  14. public class MySQL {
  15.  
  16. public static String username;
  17. public static String password;
  18. public static String database;
  19. public static String host;
  20. public static String port;
  21. public static Connection con;
  22.  
  23. public static void connect(){
  24. if(!isConnected()) {
  25. try {
  26. con = DriverManager.getConnection("jdbc:mysql//" + host + ":" + port + "/" + database, username, password);
  27. Bukkit.getConsoleSender().sendMessage(Main.getInstance().prefix + "§aMySQL verbunden§7!");
  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(Main.getInstance().prefix + "§cMySQL beendet§7!");
  42. } catch (SQLException e) {
  43. e.printStackTrace();
  44. }
  45.  
  46. }
  47. }
  48.  
  49. public static boolean isConnected(){
  50. return con !=null;
  51. }
  52.  
  53. public static void createTable(){
  54. if(isConnected()){
  55. try {
  56. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS BannedPlayers (Spielername VARCHAR(100), UUID VARCHAR(100), Ende VARCHAR(100), Grund VARCHAR(100))");
  57. } catch (SQLException e) {
  58. e.printStackTrace();
  59. }
  60. }
  61. }
  62.  
  63. public static void Upadate(String qry) {
  64. if(MySQL.isConnected()){
  65. try {
  66. con.createStatement().executeUpdate(qry);
  67. } catch (SQLException e) {
  68. e.printStackTrace();
  69. }
  70. }
  71. }
  72.  
  73. public static ResultSet getResult(String qry){
  74. if(MySQL.isConnected()){
  75. try {
  76. return con.createStatement().executeQuery(qry);
  77. } catch (SQLException e) {
  78. e.printStackTrace();
  79. }
  80.  
  81. }
  82. return null;
  83. }
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement