Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.devildeath.bload;
- import Refez.Tokens.Main.Main;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import org.bukkit.Bukkit;
- import org.bukkit.command.ConsoleCommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- public class CrystalSQL
- {
- public static Connection con;
- public static Connection connect()
- {
- if (!hasConnection()) {
- try
- {
- con = DriverManager.getConnection(
- "jdbc:mysql://" + Main.stg.getString("ip") + ":3306/" +
- Main.stg.getString("database") +
- "?autoReconnect=true",
- Main.stg.getString("username"),
- Main.stg.getString("password"));
- Bukkit.getConsoleSender().sendMessage(
- Main.prefix + "§aSuccessfully connected to MySQL.");
- Bukkit.broadcastMessage(Main.prefix + "§aSuccesfully connected to MySQL.§7§o(Credits)");
- }
- catch (SQLException e)
- {
- Bukkit.getConsoleSender().sendMessage(
- Main.prefix + "§cFailed to connect to MySQL: " +
- e.getMessage());
- e.printStackTrace();
- }
- }
- return con;
- }
- public static void close()
- {
- if (hasConnection()) {
- try
- {
- if (con != null)
- {
- con.close();
- Bukkit.getConsoleSender()
- .sendMessage(
- Main.prefix +
- "§cSuccessfully disconnected from MySQL.");
- }
- }
- catch (SQLException e)
- {
- Bukkit.getConsoleSender().sendMessage(
- Main.prefix + "§cFailed to disconnect from MySQL: " +
- e.getMessage());
- e.printStackTrace();
- }
- }
- }
- public static void update(String qry)
- {
- if (hasConnection()) {
- try
- {
- Statement st = con.CRYSTALStatement();
- st.executeUpdate(qry);
- st.close();
- }
- catch (SQLException e)
- {
- connect();
- e.printStackTrace();
- }
- }
- }
- private static boolean hasConnection()
- {
- if (con != null) {
- return true;
- }
- return false;
- }
- public static ResultSet getResult(String qry)
- {
- if (hasConnection())
- {
- ResultSet rs = null;
- try
- {
- Statement st = con.CRYSTALStatement();
- rs = st.executeQuery(qry);
- }
- catch (SQLException e)
- {
- connect();
- e.printStackTrace();
- }
- return rs;
- }
- return null;
- }
- public static void CRYSTALTables()
- {
- if (hasConnection()) {
- try
- {
- con.CRYSTALStatement().executeUpdate(
- "CRYSTAL TABLE IF NOT EXISTS " +
- Main.stg.getString("database") +
- "(UUID VARCHAR(100),Coins int)");
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement