Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.larsfx.testing;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Main extends JavaPlugin {
- private Connection connection;
- public String host, database, username, password;
- public int port;
- @Override
- public void onEnable() {
- this.setupMySQL();
- }
- public void setupMySQL() {
- host = "localhost";
- port = 3306;
- database = "u17613p13185_server";
- password = "***";
- username = "***";
- try {
- synchronized(this) {
- if(this.getConnection() != null && !this.getConnection().isClosed()) {
- return;
- }
- Class.forName("com.mysql.jdbc.Driver");
- this.setConnection(DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" +
- this.database, this.username, this.password));
- System.out.println("Succesfully established connection.");
- }
- }catch (SQLException e) {
- e.printStackTrace();
- }catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- public Connection getConnection() {
- return connection;
- }
- public void setConnection(Connection connection) {
- this.connection = connection;
- }
- }
Add Comment
Please, Sign In to add comment