Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MYSQL extends JavaPlugin {
- private Connection connection;
- public String host, database, username, password;
- public int database_port;
- @Override
- public void onEnable() {
- setupMYSQL();
- }
- private void setupMYSQL() {
- host = "localhost";
- database = "test";
- username = "root";
- password = "password";
- database_port = 3306;
- setupConnection();
- }
- private void setupConnection() {
- try {
- synchronized (this) {
- if (getConnection() != null && !getConnection().isClosed()) {
- return;
- }
- Class.forName("com.mysql.jdbc.Driver");
- setConnection(DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.database_port + "/" + this.database, this.username, this.password));
- Bukkit.getConsoleSender().sendMessage("§aMYSQL Connection Establish");
- }
- } 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