Advertisement
EntenPlayz

Untitled

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