package examenes.examen20250509.controlador;

import java.sql.Connection;
import java.sql.DriverManager;

public class GestorConexiones {

    private static Connection openConnection;

    private static String getMySQLConnectionString() {
        String host = "127.0.0.1:3310";
        String schema = "conciertos_grupos_salas";
        String properties = "?autoReconnect=true&serverTimezone=Europe/Madrid&useSSL=False&allowPublicKeyRetrieval=TRUE";
        String user = "root";
        String password = "1234";

        return "jdbc:mysql://" + user + ":" + password + "@" + host + "/" + schema + properties;
    }

    public static Connection getConnection() {
        if (openConnection == null) {
            try {
                //Class.forName(getMySQLDriver());
                openConnection = DriverManager.getConnection(getMySQLConnectionString());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return openConnection;
    }

    public static String getMySQLDriver() {
        return "com.mysql.cj.jdbc.Driver";
    }

}
