Advertisement
Guest User

Untitled

a guest
Jan 15th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1.     public class Main extends JavaPlugin implements Listener {
  2.  
  3.     private Connection connection;
  4.     private String host, database, username, password;
  5.     private int port;
  6.  
  7. @Override
  8.     public void onEnable() {
  9.         host = "localhost";
  10.         port = 3306;
  11.         database = "";
  12.         username = "root";
  13.         password = "";    
  14.         try {    
  15.             openConnection();
  16.             Statement statement = connection.createStatement();          
  17.         } catch (ClassNotFoundException e) {
  18.             e.printStackTrace();
  19.         } catch (SQLException e) {
  20.             e.printStackTrace();
  21.         }
  22. }
  23.     public void openConnection() throws SQLException, ClassNotFoundException {
  24.         if (connection != null && !connection.isClosed()) {
  25.             return;
  26.         }
  27.      
  28.         synchronized (this) {
  29.             if (connection != null && !connection.isClosed()) {
  30.                 return;
  31.             }
  32.             Class.forName("com.mysql.jdbc.Driver");
  33.             connection = DriverManager.getConnection("jdbc:mysql://" + this.host+ ":" + this.port + "/" + this.database, this.username, this.password);
  34.         }
  35.     }  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement