Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.7 kB
1
Indexable
Never
package it.eccessivo.deluxebank;

import org.bukkit.Bukkit;

import java.sql.Statement;
import java.sql.*;

public class MySQL {
    public static Connection connection;
    static String database = DeluxeBank.getInstance().getConfig().getString("MySQL.database");
    static String url = "jdbc:mysql://85.202.160.143/" + database;
    static String username = DeluxeBank.getInstance().getConfig().getString("MySQL.username");
    static String password = DeluxeBank.getInstance().getConfig().getString("MySQL.password");

    public static void connect(){

        try {
            connection = DriverManager.getConnection(url, username, password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static Connection getDatabase(){
        return connection;
    }

    public static void createBankTable(){
        try (Connection conn = DriverManager.getConnection(url, username, password)) {

            String sql = "CREATE TABLE IF NOT EXISTS banks(uuid VARCHAR(36) primary key, balance double, card VARCHAR(255), pin int, status VARCHAR(255))";

            try (Statement stmt = conn.createStatement()) {
                stmt.executeUpdate(sql);
                Bukkit.getConsoleSender().sendMessage("§aTabella banca creata");
                stmt.close();
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static void disconnect(){
        try {
            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }