Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main extends JavaPlugin {
- private Connection connection;
- public String host, database, username, password;
- public int port;
- public void onEnable() {
- loadConfig();
- mysqlSetup();
- }
- public void onDisable() {
- }
- private void loadConfig() {
- getConfig().options().copyDefaults(true);
- saveConfig();
- }
- public void mysqlSetup(){
- host = "localhost";
- port = 3306;
- database = "test";
- username = "root";
- password = "password";
- 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 + "[MySQL] Server 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