package mineplex.hub; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; import mineplex.core.common.util.NautHashMap; import mineplex.core.status.ServerStatusData; import org.bukkit.Bukkit; import org.bukkit.entity.Player; public class HubRepository { private static Object _connectionLock = new Object(); private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/Mineplex?autoReconnect=true&failOverReadOnly=false&maxReconnects=10"; private String _userName = "root"; private String _password = "tAbechAk3wR7tuTh"; private boolean _us = true; private static String CREATE_NEWS_TABLE = "CREATE TABLE IF NOT EXISTS newsList (id INT NOT NULL AUTO_INCREMENT, newsString VARCHAR(256), newsPosition INT, PRIMARY KEY (id));"; private static String RETRIEVE_NEWS_ENTRIES = "SELECT newsString, newsPosition FROM newsList;"; private static String ADD_NEWS_ENTRY = "INSERT INTO newsList (newsString, newsPosition) VALUES(?,?);"; private static String SET_NEWS_ENTRY = "UPDATE newsList SET newsString = ? WHERE newsPosition = ?;"; private static String DELETE_NEWS_ENTRY = "DELETE FROM newsList WHERE newsPosition = ?;"; private Connection _connection = null; public void initialize(boolean us) { _us = us; PreparedStatement preparedStatement = null; try { Class.forName("com.mysql.jdbc.Driver"); _connection = DriverManager.getConnection(_connectionString, _userName, _password); // Create table preparedStatement = _connection.prepareStatement(CREATE_NEWS_TABLE); preparedStatement.execute(); } catch (Exception exception) { exception.printStackTrace(); } finally { if (preparedStatement != null) { try { preparedStatement.close(); } catch (SQLException e) { e.printStackTrace(); } } } } }