Advertisement
Guest User

Untitled

a guest
Oct 9th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. public Connection con;
  2. private FileConfiguration cfgmysql = XeventoFFA.getInstance().filemanager.getMySQLConfig();
  3.  
  4. public void connect() {
  5. if(!isConnected()) {
  6.  
  7. String HOST = cfgmysql.getString("mysql.host");
  8. String DATABASE = cfgmysql.getString("mysql.datenbank");
  9. String USER = cfgmysql.getString("mysql.user");
  10. String PASSWORD = cfgmysql.getString("mysql.passwort");
  11.  
  12. try {
  13. con = DriverManager.getConnection("jdbc:mysql://" + HOST + ":3306/" + DATABASE + "?autoReconnect=true", USER, PASSWORD);
  14. System.out.println("[MySQL] Verbindung wurde aufgebaut");
  15. } catch (SQLException e) {
  16. e.printStackTrace();
  17. }
  18. }
  19. }
  20.  
  21. public void disconnect() {
  22. if(isConnected()) {
  23. try {
  24. con.close();
  25. System.out.println("[MySQL] Verbindung wurde geschlossen");
  26. } catch(SQLException e) {
  27. e.printStackTrace();
  28. }
  29. }
  30. }
  31.  
  32. public boolean isConnected() {
  33. return(con == null ? false : true);
  34. }
  35.  
  36. public Connection getConnection() {
  37. return con;
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement