Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package roleplay.mysql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.plugin.Plugin;
- import roleplay.main.Main;
- public class MysqlConnect {
- private Connection connection;
- public String host, data, database, username, password, table;
- public int port;
- Plugin plugin = Main.getPlugin(Main.class);
- public void mysqlSetup() {
- host = plugin.getConfig().getString("host");
- port = plugin.getConfig().getInt("port");
- database = plugin.getConfig().getString("database");
- username = plugin.getConfig().getString("username");
- password = plugin.getConfig().getString("password");
- table = plugin.getConfig().getString("table");;
- try {
- synchronized (this) {
- if (getConnection() != null && !getConnection().isClosed()) {
- return;
- }
- Class.forName("com.mysql.jdbc.Driver");
- setConnection(
- DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database,
- this.username, this.password));
- Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "[Roleplay] MYSQL connected!");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- public Connection getConnection() {
- return connection;
- }
- public void setConnection(Connection connection) {
- this.connection = connection;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement