Advertisement
Guest User

DB?

a guest
Mar 9th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. package com.triblion.spigot;
  2.  
  3. import org.bukkit.plugin.java.JavaPlugin;
  4.  
  5. import java.sql.*;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8.  
  9. public class Test extends JavaPlugin {
  10.  
  11. private Connection connection;
  12. private String host, database, username, password
  13. private int port;
  14.  
  15. @Override
  16. public void onEnable() {
  17. host = "localhost";
  18. port = 3306;
  19. database ="FrozenSuite";
  20. username = "test";
  21. password = "Password";
  22. try {
  23. Connect();
  24. Statement statement = connection.createStatement();
  25. ResultSet result = statement.executeQuery("SELECT * FROM Players WHERE balance = 0;");
  26. List<String> playersBalance = new ArrayList<String>();
  27. while (result.next()) {
  28. String name = result.getString("PlayerName");
  29. playersBalance.add(name);
  30. }
  31. statement.executeUpdate("INSERT INTO Players (PlayerName, balance ) VALUES ('PlayerName', 100);");
  32. } catch (SQLException e) {
  33. e.printStackTrace();
  34. } catch (ClassNotFoundException e) {
  35. e.printStackTrace();
  36. }
  37. }
  38.  
  39. @Override
  40. public void onDisable() {
  41.  
  42. }
  43.  
  44. private void Connect() throws SQLException, ClassNotFoundException {
  45. if (connection !=null && !connection.isClosed()) {
  46. return;
  47. }
  48.  
  49. synchronized (this) {
  50. if(connection !=null && !connection.isClosed()) {
  51. return;
  52. }
  53. Class.forName("com.mysql.jdbc.Driver");
  54. connection = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password);
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement