Advertisement
Guest User

Untitled

a guest
Apr 4th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. public static String username = "";
  2. public static String passwort = "";
  3. public static String host = "";
  4. public static int port = 3360;
  5. public static String database = "";
  6.  
  7. public static Connection con;
  8.  
  9. public static void connect() {
  10. if(!isConnected()) {
  11. try {
  12. con = DriverManager.getConnection("jdbc:mysql://"+host+":"+port+"/"+database, username, passwort);
  13. Messages.bungeelogger(Level.INFO, "§5MySQL §7- §aDie Verbindung steht nun!");
  14. } catch (SQLException e) {
  15. e.printStackTrace();
  16. Messages.bungeelogger(Level.SEVERE, "§5MySQL §7- §cEs konnte keine Verbindung hergestellt werden!");
  17. }
  18. }
  19. }
  20.  
  21. public static void close() {
  22. if(!isConnected()) {
  23. try {
  24. con.close();
  25. Messages.bungeelogger(Level.INFO, "§5MySQL §7- §eDie Verbindung wurde geschlossen!");
  26. } catch (SQLException e) {
  27. e.printStackTrace();
  28. Messages.bungeelogger(Level.SEVERE, "§5MySQL §7- §cEs wurde keine Aktive Verbindung gefunden!");
  29. }
  30. }
  31. }
  32.  
  33. public static boolean isConnected() {
  34. return con != null;
  35. }
  36.  
  37. public static void update(String qry) {
  38. try {
  39. PreparedStatement ps = con.prepareStatement(qry);
  40. ps.executeUpdate();
  41. } catch (SQLException e) {
  42. e.printStackTrace();
  43. }
  44. }
  45.  
  46. public static ResultSet getResult(String qry) {
  47. try {
  48. PreparedStatement ps = con.prepareStatement(qry);
  49. return ps.executeQuery();
  50. } catch (SQLException e) {
  51. e.printStackTrace();
  52. }
  53. return null;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement