Advertisement
Guest User

Untitled

a guest
Jun 6th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. package tk.Rauno.XPBank;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7.  
  8. public class MySQL {
  9.  
  10. public static String host;
  11. public static String port;
  12. public static String database;
  13. public static String username;
  14. public static String password;
  15. public static Connection con;
  16. public static void connect() {
  17. if(!isConnected()) {
  18. try {
  19. con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
  20. System.out.println(main.prefix + " MySQL is now connected.");
  21. } catch (SQLException e) {
  22. e.printStackTrace();
  23. }
  24. }
  25. }
  26.  
  27. public static void disconnect() {
  28. if(isConnected()) {
  29. try {
  30. con.close();
  31. } catch (SQLException e) {
  32. e.printStackTrace();
  33. }
  34. }
  35. }
  36.  
  37. public static boolean isConnected() {
  38. return (con == null ? false : true);
  39. }
  40.  
  41. public static Connection getConnection() {
  42. return con;
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement