Advertisement
EntenPlayz

Untitled

May 23rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. public String Host;
  2. public String Database;
  3. public String Username;
  4. public String Password;
  5. public Connection con;
  6.  
  7. public void setMySQL(String Host, String Database, String Username, String Password) {
  8. this.Username = Username;
  9. this.Password = Password;
  10. this.Database = Database;
  11. this.Host = Host;
  12. }
  13.  
  14. public void connect() {
  15. if(!isConnected()) {
  16. try {
  17. con = DriverManager.getConnection("jdbc:mysql://" + Host + ":3306/" + Database + "?autoReconnect=true", Username, Password);
  18. Bukkit.getConsoleSender().sendMessage("[MySQL] Erfolgreich zur MySQL-Datenbank verbunden");
  19. } catch(SQLException e) {
  20. Bukkit.getConsoleSender().sendMessage("[MySQL] Es konnte nicht zur MySQL-Datenbank verbunden werden, bitte überprüfe deine Einstellungen");
  21. }
  22. }
  23. }
  24.  
  25. public void close() {
  26. if(isConnected()) {
  27. try {
  28. con.close();
  29. con = null;
  30. Bukkit.getConsoleSender().sendMessage("[MySQL] Die MySQL Verbindung wurde getrennt");
  31. } catch(SQLException e) {
  32. Bukkit.getConsoleSender().sendMessage("[MySQL] Die MySQL Verbindung konnte nicht geschlossen werden");
  33. }
  34. }
  35. }
  36.  
  37. public boolean isConnected() {
  38. return con != null;
  39. }
  40.  
  41. public void update(String qry) {
  42. if(isConnected()) {
  43. try {
  44. con.createStatement().executeUpdate(qry);
  45. } catch(SQLException e) {
  46. e.printStackTrace();
  47. }
  48. }
  49. }
  50.  
  51. public ResultSet getResult(String qry) {
  52. try {
  53. return con.createStatement().executeQuery(qry);
  54. }
  55. catch (SQLException e) {
  56. e.printStackTrace();
  57. }
  58. return null;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement