Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. package MySQL;
  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 String username;
  10. public static String password;
  11. public static String database;
  12. public static String host;
  13. public static String port;
  14.  
  15. public static Connection con;
  16.  
  17.  
  18. public static Connection getConnection() {
  19. return con;
  20. }
  21.  
  22. public static void connect() {
  23. if(!isConnected()) {
  24. try {
  25. con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
  26. System.out.println("[MySQL] Verbindung aufgebaut!");
  27. } catch (SQLException e) {
  28. e.printStackTrace();
  29. }
  30. }
  31. }
  32.  
  33. public static void disconnect() {
  34. if(isConnected()) {
  35. try {
  36. con.close();
  37. System.out.println("[MySQL] Verbindung geschlossen!");
  38. } catch (SQLException e) {
  39. e.printStackTrace();
  40. }
  41. }
  42. }
  43.  
  44. public static boolean isConnected() {
  45. return (con == null ? false : true);
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement