Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MySQL {
- public static String USER = Main.cfg.getString("MySQL.user");
- public static String HOST = Main.cfg.getString("MySQL.host");
- public static String PASSWORD = Main.cfg.getString("MySQL.password");
- public static String DATABASE = Main.cfg.getString("MySQL.database");
- public static Connection con;
- // Connect to the MYSQL-Database
- public static void connect() {
- try {
- con = DriverManager.getConnection(
- "jdbc:mysql://" + HOST + ":3306/" + DATABASE,
- USER, PASSWORD);
- Server server = Bukkit.getServer();
- ConsoleCommandSender console = server.getConsoleSender();
- console.sendMessage(ChatColor.DARK_PURPLE + "MySQL-Connection: "+ ChatColor.GREEN + "Connected!");
- } catch (SQLException localSQLException) { localSQLException.printStackTrace(); }
- }
- // Close the MYSQL-Connection
- public static void close() {
- if (con != null) {
- try {
- con.close();
- } catch (SQLException localSQLException) { localSQLException.printStackTrace(); }
- }
- }
- //Check if the MYSQL-Connection closed!
- // Return true if the Connection was closed. false if the connection is alive
- public static boolean isClosed() {
- try {
- return con.isClosed();
- } catch (SQLException localSQLException) { localSQLException.printStackTrace(); }
- return false;
- }
- //Creates an UPDATE-SQL Query!
- public static void Update(String qry) {
- if ((con == null) || (isClosed())) {
- connect();
- }
- try {
- Statement stmt = con.createStatement();
- stmt.executeUpdate(qry);
- } catch (SQLException localSQLException) { localSQLException.printStackTrace(); }
- }
- /// MYSQL Query ///
- /// Return the ResultSet ///
- public static ResultSet Query(String qry) {
- if ((con == null) || (isClosed())) {
- connect();
- }
- ResultSet rs = null;
- try {
- Statement stmt = con.createStatement();
- rs = stmt.executeQuery(qry);
- } catch (SQLException localSQLException) { localSQLException.printStackTrace(); }
- return rs;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement