Advertisement
Guest User

MySQL Klasse 2.0

a guest
Dec 22nd, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. public static String username = "root";
  2. public static String pass = "";
  3. public static String database = "FutoraMC";
  4. public static String host = "localhost";
  5.  
  6. public static Connection con;
  7.  
  8. public static void connect(){
  9.  
  10. try {
  11. con = DriverManager.getConnection("jdbc:mysql://"+host+":3306"+"/"+database, username, pass);
  12. BungeeCord.getInstance().getConsole().sendMessage("§f[§eMySQL§f] §aConnected");
  13. createTable();
  14. } catch (SQLException e) {
  15. e.printStackTrace();
  16. Bukkit.getConsoleSender().sendMessage("§f[§eMySQL§f] §cError while connecting");
  17. }
  18. }
  19.  
  20. public static void close(){
  21. if(!isConnected()){
  22. try {
  23. con.close();
  24. Bukkit.getConsoleSender().sendMessage("§f[§eMySQL§f] §cDisconnected");
  25. } catch (SQLException e) {
  26. e.printStackTrace();
  27. Bukkit.getConsoleSender().sendMessage("§f[§eMySQL§f] §cError while disconnecting");
  28.  
  29. }
  30.  
  31. }
  32. }
  33.  
  34. public static boolean isConnected(){
  35. return con != null;
  36. }
  37.  
  38. public static void createTable(){
  39.  
  40.  
  41. if(isConnected()){
  42. try {
  43. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS PlayerInfo (Spielername VARCHAR(100), " +
  44. "JoinMe INTEGER(100))");
  45.  
  46.  
  47. Bukkit.getConsoleSender().sendMessage("§f[§eMySQL§f] §6Tabellen erstellt, sofern noch nicht vorhanden");
  48. } catch (SQLException e) {
  49. e.printStackTrace();
  50. }
  51. }
  52.  
  53. }
  54.  
  55. public static void update(String qry){
  56. if(isConnected()){
  57. try {
  58. con.createStatement().executeUpdate(qry);
  59. } catch (SQLException e) {
  60. e.printStackTrace();
  61. }
  62. }
  63. }
  64.  
  65. public static ResultSet getResult(String qry){
  66. if(isConnected()){
  67. try {
  68. return con.createStatement().executeQuery(qry);
  69. } catch (SQLException e) {
  70. e.printStackTrace();
  71. }
  72. }
  73. return null;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement