Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.maiky.tokens.engine;
- import net.maiky.tokens.tokens;
- import org.bukkit.Bukkit;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class Mysql {
- private String host = "";
- private String port = "";
- private String database = "";
- private String username = "";
- private String password = "";
- private Connection connection;
- public tokens main;
- public Mysql(tokens main) {
- this.main = main;
- host = main.getConfig().getString("MySQL.host");
- port = main.getConfig().getString("MySQL.port");
- database= main.getConfig().getString("MySQL.database");
- username = main.getConfig().getString("MySQL.user");
- password = main.getConfig().getString("MySQL.password");
- }
- public boolean isConnected() {
- return (connection == null ? false : true);
- }
- public void connect() throws ClassNotFoundException, SQLException {
- if(!isConnected()) {
- connection = DriverManager.getConnection("jdbc:mysql://" +
- host + ":" + port + "/" + database + "?useSSL=false",
- username, password);
- }
- }
- public void disconnect() {
- if(isConnected()) {
- try {
- connection.close();
- } catch (SQLException e) {
- //e.printStackTrace();
- }
- }
- }
- public Connection getConnection() {
- return connection;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement