Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. package me.playgame.nickdetector.sql;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class sql {
  8.  
  9. public static String host = "localhost";
  10. public static int port = 3306;
  11. public static String database = "test";
  12. public static String username = "root";
  13. public static String password = "test";
  14. public static Connection con;
  15.  
  16. public static void connect(){
  17. if(!isConnected()){
  18. try {
  19. con = DriverManager.getConnection("jdbc:mysql://" + host + "?autoReconnect=true", username, password);
  20. System.out.println("§4Die Verbindung zur MySQL Datenbank wurde erfolgreich hergestellt");
  21. } catch (SQLException e) {
  22. System.out.println("§4Die Verbindung zur MySQL Datenbank ist Fehlgeschlagen");
  23. e.printStackTrace();
  24. }
  25. }
  26. }
  27.  
  28. public static void disconnect(){
  29. if(isConnected()){
  30. try {
  31. con.close();
  32. } catch (Exception e) {
  33. System.out.println("§4Die Verbindung zur MySQL Datenbank wurde geschlossen");
  34. }
  35. }
  36. }
  37.  
  38. public static boolean isConnected(){
  39. return (con == null ? false : true);
  40. }
  41.  
  42. public static Connection getConnection(){
  43. return con;
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement