Advertisement
Guest User

Untitled

a guest
Aug 6th, 2016
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. package me.dubdesigns.sql;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7.  
  8. import org.bukkit.plugin.java.JavaPlugin;
  9.  
  10. public class Main extends JavaPlugin {
  11.  
  12.     private Connection connection;
  13.     private String host, database, username, password;
  14.     private int port;
  15.  
  16.         @Override
  17.         public void onEnable() {
  18.             host = "151.80.58.113";
  19.             port = 3306;
  20.             database = "SkyBlock";
  21.             username = "skyblock";
  22.             password = "***";    
  23.             try {    
  24.                 openConnection();
  25.                 Statement statement = connection.createStatement();    
  26.                 statement.executeUpdate("CREATE TABLE IF NOT EXISTS Levels(UUID varchar(255), Name VARCHAR(255), Lvl int, XP int)");
  27.             } catch (ClassNotFoundException e) {
  28.                 e.printStackTrace();
  29.             } catch (SQLException e) {
  30.                 e.printStackTrace();
  31.             }
  32.         }
  33.    
  34.         public void openConnection() throws SQLException, ClassNotFoundException {
  35.         if (connection != null && !connection.isClosed()) {
  36.             return;
  37.         }
  38.         synchronized (this) {
  39.             if (connection != null && !connection.isClosed()) {
  40.                 return;
  41.             }
  42.             Class.forName("com.mysql.jdbc.Driver");
  43.             connection = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password);
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement