Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DatabaseManager {
- private final Clans plugin;
- @Getter
- private static Connection connection;
- public DatabaseManager(final Clans plugin) {
- this.plugin = plugin;
- }
- public void connect() {
- if (!isConnected())
- try {
- connection = DriverManager.getConnection("jdbc:mysql://" + this.plugin.getData().getMysqlHostName() + ":" + this.plugin.getData().getMysqlPort() + "/" + this.plugin.getData().getMysqlDatabase() + "?sslmode=require", this.plugin.getData().getMysqlUsername(), this.plugin.getData().getMysqlPassword());
- System.out.println("clans connected to database");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static void disconnect() {
- if (isConnected())
- try {
- connection.close();
- System.out.println("clans disconnected from database");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static boolean isConnected() {
- return !(connection == null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement