Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. package de.melonmc.tntrun.Nick;
  2.  
  3. import java.sql.*;
  4.  
  5. /**
  6. * Created by User on 06.02.2017.
  7. */
  8. public class MySQL {
  9.  
  10.  
  11. public static String host = "localhost";
  12. public static String port = "3306";
  13. public static String database = "AutoNick";
  14. public static String username = "RufixHD";
  15. public static String password = "ldH39z7#";
  16. public static Connection con;
  17.  
  18. public static void connect() {
  19. if(!isConnected()) {
  20. try {
  21. con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true", username, password);
  22. System.out.println("[MySQL] Verbindung aufgebaut!!!");
  23. } catch (SQLException e) {
  24. e.printStackTrace();
  25. }
  26. }
  27. }
  28.  
  29. public static void disconnect() {
  30. if(isConnected()) {
  31. try {
  32. con.close();
  33. System.out.println("Verbindung getrennt");
  34. } catch (SQLException e) {
  35. e.printStackTrace();
  36. }
  37. }
  38. }
  39.  
  40. public static boolean isConnected() {
  41. return (con == null ? false : true);
  42. }
  43.  
  44.  
  45.  
  46. public static int getNick(String uuid) {
  47. try {
  48. PreparedStatement ps = con.prepareStatement("SELECT Nick FROM Autonick WHERE UUID = ?");
  49. ps.setString(1, uuid);
  50. ResultSet rs = ps.executeQuery();
  51. while (rs.next()) {
  52. return rs.getInt("Nick");
  53. }
  54. } catch (SQLException e) {
  55. e.printStackTrace();
  56. }
  57. return -1;
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement