Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. public static Connection con;
  2.  
  3. public static void connect(String host, String port, String database, String username, String password)
  4. {
  5. if (!isConnected()) {
  6. try
  7. {
  8. con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
  9. System.out.println("nxtKevu MYSQL connected");
  10. }
  11. catch (SQLException e)
  12. {
  13. System.out.println("nxtKevu MYSQL FAILED");
  14. e.printStackTrace();
  15. }
  16. }
  17. }
  18.  
  19. public static void disconnect()
  20. {
  21. if (isConnected()) {
  22. try
  23. {
  24. con.close();
  25. System.out.println("nxtKevu MYSQL disconnected");
  26. }
  27. catch (SQLException e)
  28. {
  29. e.printStackTrace();
  30. }
  31. }
  32. }
  33.  
  34. public static boolean isConnected()
  35. {
  36. return con != null;
  37. }
  38.  
  39. public static Connection getCon()
  40. {
  41. return con;
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement