Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main extends JavaPlugin implements Listener {
- private Connection connection;
- private String host, database, username, password;
- private int port;
- @Override
- public void onEnable() {
- host = "localhost";
- port = 3306;
- database = "";
- username = "root";
- password = "";
- try {
- openConnection();
- Statement statement = connection.createStatement();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void openConnection() throws SQLException, ClassNotFoundException {
- if (connection != null && !connection.isClosed()) {
- return;
- }
- synchronized (this) {
- if (connection != null && !connection.isClosed()) {
- return;
- }
- Class.forName("com.mysql.jdbc.Driver");
- connection = DriverManager.getConnection("jdbc:mysql://" + this.host+ ":" + this.port + "/" + this.database, this.username, this.password);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement