Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.dubdesigns.sql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Main extends JavaPlugin {
- private Connection connection;
- private String host, database, username, password;
- private int port;
- @Override
- public void onEnable() {
- host = "151.80.58.113";
- port = 3306;
- database = "SkyBlock";
- username = "skyblock";
- password = "***";
- try {
- openConnection();
- Statement statement = connection.createStatement();
- statement.executeUpdate("CREATE TABLE IF NOT EXISTS Levels(UUID varchar(255), Name VARCHAR(255), Lvl int, XP int)");
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void openConnection() throws SQLException, ClassNotFoundException {
- if (connection != null && !connection.isClosed()) {
- return;
- }
- synchronized (this) {
- if (connection != null && !connection.isClosed()) {
- return;
- }
- Class.forName("com.mysql.jdbc.Driver");
- connection = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement