Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.IHaveSwag;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import org.bukkit.Bukkit;
- public class MySQL
- {
- private Main main;
- public MySQL(Main pl)
- {
- this.setMain(pl);
- }
- private String a;
- private String b;
- private String c;
- private String d;
- private String e;
- private static Connection connection;
- public MySQL(String a, String b, String c, String d, String e)
- {
- this.a = a;
- this.b = b;
- this.c = c;
- this.d = d;
- this.e = e;
- }
- public Connection openConnection()
- {
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- MySQL.connection = DriverManager.getConnection("jdbc:mysql://" + this.a + ":" + this.b + "/" + this.c, this.d, this.e);
- }
- catch (SQLException e)
- {
- Bukkit.getServer().getLogger().log(Level.SEVERE, "Error when try connect to mysql because: " + e.getMessage());
- }
- catch (ClassNotFoundException e)
- {
- Bukkit.getServer().getLogger().log(Level.SEVERE, "JDBC Driver not found!");
- }
- return MySQL.connection;
- }
- public boolean checkConnection()
- {
- return MySQL.connection != null;
- }
- public static Connection getConnection()
- {
- return MySQL.connection;
- }
- public static void closeConnection()
- {
- if (connection != null) {
- try
- {
- connection.close();
- }
- catch (SQLException e)
- {
- Bukkit.getServer().getLogger().log(Level.SEVERE, "Error when closing the MySQL!");
- }
- }
- }
- public Main getMain() {
- return main;
- }
- public void setMain(Main main) {
- this.main = main;
- }
- }
Add Comment
Please, Sign In to add comment