Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. package fr.neyox.sql;
  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. public class Main extends JavaPlugin {
  10.  
  11. private Connection conn;
  12.  
  13. public String host, database, username, password;
  14.  
  15. public int port;
  16.  
  17. @Override
  18. public void onEnable() {
  19. host = "localhost";
  20. port = 3306;
  21. database = "tutorial";
  22. username = "root";
  23. password = "password";
  24. try {
  25. synchronized (this) {
  26. if (getConn() != null && !getConn().isClosed()) {
  27. return;
  28. }
  29.  
  30. Class.forName("com.mysql.jdbc.Driver");
  31. setConn(DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password));
  32. }
  33. } catch(SQLException e) {
  34. e.printStackTrace();
  35. } catch (ClassNotFoundException e) {
  36. e.printStackTrace();
  37. }
  38. }
  39.  
  40. public Connection getConn() {
  41. return conn;
  42. }
  43.  
  44. public void setConn(Connection connection) {
  45. this.conn = connection;
  46. }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement