Guest User

Untitled

a guest
Jun 26th, 2017
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. package me.larsfx.testing;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. import org.bukkit.plugin.java.JavaPlugin;
  8.  
  9.  
  10. public class Main extends JavaPlugin {
  11.  
  12.     private Connection connection;
  13.     public String host, database, username, password;
  14.     public int port;
  15.  
  16.     @Override
  17.     public void onEnable() {
  18.         this.setupMySQL();
  19.     }
  20.  
  21.     public void setupMySQL() {
  22.         host = "localhost";
  23.         port = 3306;
  24.         database = "u17613p13185_server";
  25.         password = "***";
  26.         username = "***";
  27.        
  28.         try {
  29.            
  30.             synchronized(this) {
  31.             if(this.getConnection() != null && !this.getConnection().isClosed()) {
  32.                 return;
  33.             }
  34.             Class.forName("com.mysql.jdbc.Driver");
  35.             this.setConnection(DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" +
  36.             this.database, this.username, this.password));
  37.             System.out.println("Succesfully established connection.");
  38.             }
  39.            
  40.         }catch (SQLException e) {
  41.             e.printStackTrace();
  42.         }catch (ClassNotFoundException e) {
  43.             e.printStackTrace();
  44.         }
  45.            
  46.         }
  47.  
  48.     public Connection getConnection() {
  49.         return connection;
  50.     }
  51.     public void setConnection(Connection connection) {
  52.         this.connection = connection;
  53.     }
  54.  
  55. }
Add Comment
Please, Sign In to add comment