Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mysqlclasses;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import org.bukkit.ChatColor;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.plugin.java.JavaPlugin;
- public class MySQLAPI extends JavaPlugin {
- public String prefix = ChatColor.GOLD + "M" + ChatColor.GRAY + "y" + ChatColor.GOLD + "S" + ChatColor.GRAY + "QL" + ChatColor.GOLD + "S" + ChatColor.GRAY + "ync" + ChatColor.YELLOW + " > " + ChatColor.RESET;
- public static String MySQL_host = "";
- public static String MySQL_port = "";
- public static String MySQL_user = "";
- public static String MySQL_pass = "";
- public static String MySQL_db = "";
- public static Connection con;
- public void onEnable() {
- FileConfiguration cfg = this.getConfig();
- if(!this.getConfig().isSet("MYSQL")) {
- cfg.set("MYSQL.host", "//enter your hostname here");
- cfg.set("MYSQL.port", "//enter your port here");
- cfg.set("MYSQL.user", "//enter your username here");
- cfg.set("MYSQL.pass", "//enter your password here");
- cfg.set("MYSQL.db", "//enter your database here");
- this.saveConfig();
- } else {
- MySQL_host = cfg.getString("MYSQL.host");
- MySQL_port = cfg.getString("MYSQL.port");
- MySQL_user = cfg.getString("MYSQL.user");
- MySQL_pass = cfg.getString("MYSQL.pass");
- MySQL_db = cfg.getString("MYSQL.db");
- }
- System.out.println("[MySQL] Plugin erfolgreich aktiviert!");
- connect();
- }
- public void onDisable() {
- disconnect();
- System.out.println("[MySQL] Plugin erfolgreich deaktiviert!");
- }
- public static void connect() {
- if(!isConnected()) {
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + MySQL_host + ":" + MySQL_port + "/" + MySQL_db, MySQL_user, MySQL_pass);
- System.out.println("[MySQL] Datenbankverbindung erfolgreich aufgebaut!");
- } catch (SQLException e) {
- System.out.println("[MySQL] Datenbankverbindung gescheitert!");
- }
- }
- }
- public static void disconnect() {
- if(isConnected()) {
- try {
- con.close();
- System.out.println("[MySQL] Datenbankverbindung erfolgreich geschlossen!");
- } catch (SQLException e) {
- }
- }
- }
- public static boolean isConnected() {
- return (con == null ? false : true);
- }
- public static Connection getConnection() {
- return con;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement