Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private Main plugin;
- private Connection connection;
- public MySQLHKNH(Main plugin) {
- this.plugin = plugin;
- }
- public void mysqlSetup() {
- String host = plugin.config.getIp();
- int port = 3306;
- String database = plugin.config.getDatabaseHKNH();
- String username = plugin.config.getUsername();
- String password = plugin.config.getPassword();
- try {
- synchronized (this) {
- if (getConnection() != null && !getConnection().isClosed()) {
- return;
- }
- Class.forName("com.mysql.cj.jdbc.Driver");
- setConnection(
- DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true&serverTimezone=UTC", username, password));
- }
- } catch (SQLException | ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- private Connection getConnection() {
- return connection;
- }
- private void setConnection(Connection connection) {
- this.connection = connection;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement