Advertisement
Guest User

Untitled

a guest
Jan 7th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. public class MySQL {
  2.  
  3. public static String host;
  4. public static String port;
  5. public static String database;
  6. public static String username;
  7. public static String password;
  8. public static Connection con;
  9.  
  10.  
  11.  
  12. public static void connect() {
  13.  
  14. if(!isConnected()) {
  15. try {
  16. con = DriverManager.getConnection("jdbc:mysql://"
  17. + host
  18. + ":"
  19. + port
  20. + "/"
  21. + database,
  22. username,
  23. password);
  24. System.out.println("MySQL verbunden!");
  25. } catch (SQLException e) {
  26. e.printStackTrace();
  27. }
  28. }
  29.  
  30. }
  31. public static void disconnect() {
  32. if(isConnected()) {
  33. try {
  34. con.close();
  35. System.out.println("MySQL getrennt!");
  36. } catch (SQLException e) {
  37. e.printStackTrace();
  38. }
  39. }
  40. }
  41. public static boolean isConnected() {
  42. return (con == null ? false : true);
  43. }
  44.  
  45.  
  46.  
  47. public static Connection getConnection() {
  48. return con;
  49. }
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement