Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.devlection.lib;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import static de.devlection.lib.Color.*;
- public class MySQL {
- private static final String host = "localhost";
- private static final int port = 3306;
- private static final String database = "MLGRush";
- private static final String username = "localhost";
- private static final String password = "root";
- private static Connection connection;
- private static final String PREFIX = "[MySQL] ";
- public static void connect() {
- if (!(isConnected())) {
- try {
- connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
- System.out.println(PREFIX + GREEN + "Verbindung aufgebaut!");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void disConnect() {
- if (isConnected()) {
- try {
- connection.close();
- System.out.println(PREFIX + GREEN + "Verbindung geschlossen!");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- private static boolean isConnected() {
- return connection != null;
- }
- public static void createTable() {
- try {
- connection.prepareStatement("CREATE TABLE IF NOT EXISTS mlgrush " +
- "(UUID VARCHAR(100), " +
- "playername VARCHAR(100), " +
- "rank INT(100), " +
- "wins INT(100), " +
- "looses INT(100), " +
- "playedgames INT(100), " +
- "kills INT(100), " +
- "deaths INT(100))").executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment