Guest User

MySQL

a guest
Jun 22nd, 2018
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. package de.devlection.lib;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import static de.devlection.lib.Color.*;
  7.  
  8. public class MySQL {
  9.  
  10. private static final String host = "localhost";
  11. private static final int port = 3306;
  12. private static final String database = "MLGRush";
  13. private static final String username = "localhost";
  14. private static final String password = "root";
  15. private static Connection connection;
  16. private static final String PREFIX = "[MySQL] ";
  17.  
  18. public static void connect() {
  19. if (!(isConnected())) {
  20. try {
  21. connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
  22. System.out.println(PREFIX + GREEN + "Verbindung aufgebaut!");
  23. } catch (SQLException e) {
  24. e.printStackTrace();
  25. }
  26. }
  27. }
  28.  
  29. public static void disConnect() {
  30. if (isConnected()) {
  31. try {
  32. connection.close();
  33. System.out.println(PREFIX + GREEN + "Verbindung geschlossen!");
  34. } catch (SQLException e) {
  35. e.printStackTrace();
  36. }
  37. }
  38. }
  39.  
  40. private static boolean isConnected() {
  41. return connection != null;
  42. }
  43.  
  44. public static void createTable() {
  45. try {
  46. connection.prepareStatement("CREATE TABLE IF NOT EXISTS mlgrush " +
  47. "(UUID VARCHAR(100), " +
  48. "playername VARCHAR(100), " +
  49. "rank INT(100), " +
  50. "wins INT(100), " +
  51. "looses INT(100), " +
  52. "playedgames INT(100), " +
  53. "kills INT(100), " +
  54. "deaths INT(100))").executeUpdate();
  55.  
  56. } catch (SQLException e) {
  57. e.printStackTrace();
  58. }
  59. }
  60. }
Add Comment
Please, Sign In to add comment