SHARE
TWEET

Untitled

a guest Dec 6th, 2016 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package slothsec.eu.login;
  2.  
  3. import java.sql.*;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. import org.bukkit.plugin.java.JavaPlugin;
  8. import org.bukkit.scheduler.BukkitRunnable;
  9. import org.bukkit.scheduler.BukkitTask;
  10.  
  11. /**
  12.  * Created by sloth on 05.12.2016.
  13.  */
  14. public class login extends JavaPlugin {
  15.  
  16.         private Connection verbindung;
  17.         private String host, datenbank, benutzername, passwort;
  18.         private int port;
  19.  
  20.     @Override
  21.     public void onEnable(){
  22.         System.out.println("MYSQL erfolgreich gestartet!");
  23.         r.runTaskAsynchronously(this);
  24.  
  25.     }
  26.  
  27.     @Override
  28.     public void onDisable(){
  29.  
  30.     }
  31.     public void openConnection() throws SQLException, ClassNotFoundException{
  32.         if (verbindung != null && !verbindung.isClosed()){
  33.             return;
  34.         }
  35.         synchronized(this){
  36.             if (verbindung != null && !verbindung.isClosed()){
  37.                 return;
  38.             }
  39.             Class.forName("com.mysql.jdbc.Driver");
  40.             verbindung = DriverManager.getConnection("jdbc:mysql://" +this.host+ ":" + this.port + "/" + this.datenbank, this.benutzername, this.passwort);
  41.         }
  42.     }
  43.     BukkitRunnable r = new BukkitRunnable(){
  44.         @Override
  45.         public void run() {
  46.             host = "localhost";
  47.             port = 3306;
  48.             datenbank = "minecraft";
  49.             benutzername = "minecraft";
  50.             passwort = "sl0thmc";
  51.             try {
  52.                 openConnection();
  53.                 Statement statement = verbindung.createStatement();
  54.  
  55.                 ResultSet result = statement.executeQuery("SELECT * FROM Spieler;");
  56.                 List<String> players = new ArrayList<String>();
  57.  
  58.                 while (result.next()) {
  59.                     String name = result.getString("spielername");
  60.                     players.add(name);
  61.                     System.out.println(name);
  62.                 }
  63.             } catch (ClassNotFoundException e) {
  64.                 e.printStackTrace();
  65.             } catch (SQLException e) {
  66.                 e.printStackTrace();
  67.             }
  68.         }
  69.     };
  70.  
  71. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top