Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(!getDataFolder().exists()) {
- getDataFolder().mkdir();
- }
- MySQL.loadFile();
- MySQL.connect();
- MySQL.createTables();
- public class MySQL
- {
- public static String username;
- public static String password;
- public static String database;
- public static String host;
- public static String port;
- public static Connection con;
- public static void connect()
- {
- if (!isConnected()) {
- try
- {
- con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true", username, password);
- BungeeCord.getInstance().getConsole().sendMessage("§aDie MySQL Verbindung wurde erfolgreich aufgebaut§8.");
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
- public static void close()
- {
- if (isConnected()) {
- try
- {
- con.close();
- BungeeCord.getInstance().getConsole().sendMessage("§cDie MySQL Verbindung wurde erfolgreich geschlossen§8.");
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
- public static boolean isConnected()
- {
- if (con != null) {
- return true;
- }
- return false;
- }
- public static void update(String query)
- {
- PreparedStatement ps = null;
- try
- {
- ps = con.prepareStatement(query);
- ps.executeUpdate(); return;
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- finally
- {
- try
- {
- ps.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
- public static ResultSet getResult(String query)
- {
- PreparedStatement ps = null;
- ResultSet rs = null;
- try
- {
- ps = con.prepareStatement(query);
- return ps.executeQuery();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- return null;
- }
- public static void createTables()
- {
- if (isConnected()) {
- try
- {
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS cFriends_Users(Name VARCHAR(16), UUID VARCHAR(64), FList VARCHAR(20000), FRequests VARCHAR(20000), FRequest VARCHAR(10), FJump VARCHAR(10), FOnline VARCHAR(10), FSwitch VARCHAR(10), PInvite int, FConnect BIGINT, FcOnline VARCHAR(10), FServer VARCHAR(50));");
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
- public static void loadFile()
- {
- try
- {
- File file = new File(Friends.getInstance().getDataFolder(), "MySQL.yml");
- boolean created = true;
- if (!file.exists())
- {
- file.createNewFile();
- created = false;
- }
- Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
- if (!created)
- {
- config.set("mysql.Host", "localhost");
- config.set("mysql.Port", "3306");
- config.set("mysql.Database", "FreundeSystem");
- config.set("mysql.Username", "teamu");
- config.set("mysql.Password", "2ewv&Z3Ht6t5UX$");
- ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, file);
- }
- host = config.getString("mysql.Host");
- port = config.getString("mysql.Port");
- database = config.getString("mysql.Database");
- username = config.getString("mysql.Username");
- password = config.getString("mysql.Password");
- }
- catch (Exception localException) {}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement