Advertisement
Guest User

Untitled

a guest
Mar 15th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. package Duel;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class MySQL {
  8.  
  9. public static Connection con;
  10.  
  11. public static Connection connect(String host, int port, String database, String user, String password) {
  12.  
  13. try {
  14. con = DriverManager.getConnection("jdbc:mysql://"+host+":"+port+"/"+database+"?autoReconnect=true", user, password);
  15. System.out.println("[Duel] [Mysql] connection ist hergestellt!");
  16. } catch (SQLException e) {
  17. e.printStackTrace();
  18. System.out.println("[Duel] [Mysql] connection ist Fehlgeschlagen!");
  19. }
  20.  
  21. return con;
  22. }
  23.  
  24. public static void disonnect(){
  25. try {
  26. con.close();
  27. } catch (SQLException e) {
  28. e.printStackTrace();
  29. }
  30. }
  31.  
  32. public static boolean hasConnection(){
  33.  
  34. if(con != null){
  35. return true;
  36. }
  37.  
  38. return false;
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement