Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.tixmcffa.Util;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import org.bukkit.Bukkit;
- import org.bukkit.command.ConsoleCommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- public class MySQL
- {
- public static Connection Con;
- public static String DataBase = FileManager.MySQLCfg.getString("MySQL.DataBase");
- public static String Host = FileManager.MySQLCfg.getString("MySQL.Host");
- public static String Password = FileManager.MySQLCfg.getString("MySQL.Password");
- public static int Port = FileManager.MySQLCfg.getInt("MySQL.Port");
- public static String User = FileManager.MySQLCfg.getString("MySQL.User");
- public static boolean isConnected()
- {
- return Con != null;
- }
- public static void Connect()
- {
- if (!isConnected()) {
- try
- {
- Con = DriverManager.getConnection("jdbc:mysql://" + Host + ":" + 3306 + "/" + DataBase, User, Password);
- Bukkit.getConsoleSender().sendMessage("�aMySQL connection established successfully.");
- }
- catch (SQLException e)
- {
- Bukkit.getConsoleSender().sendMessage("�cFailed to connect to the MySQL database.");
- }
- }
- }
- public static void close()
- {
- if (isConnected()) {
- try
- {
- Con.close();
- Bukkit.getConsoleSender().sendMessage("�2MySQL connection closed succesfully!");
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
- public static void update(String qry)
- {
- if (isConnected()) {
- try
- {
- Con.prepareStatement(qry).executeUpdate();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
- public static ResultSet getResult(String qry)
- {
- ResultSet resultSet = null;
- if (isConnected()) {
- try
- {
- resultSet = Con.prepareStatement(qry).executeQuery();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- return resultSet;
- }
- public static void createTables()
- {
- if (isConnected()) {
- try
- {
- Con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS FFA (Playername VARCHAR(100), UUID VARCHAR(100), CurrentEffect int, LoveMove int, FireMove int, HappyArrow int, WitchArrow int, Rank int, Points int, Kills int, Deaths int)");
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment