Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package br.alkazuz.kitpvp.mysql.connection;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import org.bukkit.Bukkit;
- import br.alkazuz.kitpvp.config.Config;
- public class kMySQL
- {
- public static String ip = Config.getConfig().getString("MySQL.host");
- public static String porta = Config.getConfig().getString("MySQL.Port");
- public static String database = Config.getConfig().getString("MySQL.Database");
- public static String usuario = Config.getConfig().getString("MySQL.User");
- public static String senha = Config.getConfig().getString("MySQL.Password");
- public static Connection con;
- public static boolean jáConectado()
- {
- return con != null;
- }
- public static void conectar()
- {
- if (!jáConectado()) {
- try
- {
- con = DriverManager.getConnection("jdbc:mysql://" + ip + ":" + porta + "/" + database + "?autoReconnect=true", usuario, senha);
- Bukkit.getConsoleSender().sendMessage("§7A conexão com o §dMySQL§7 foi aceita.");
- Bukkit.getConsoleSender().sendMessage("§7O Servidor está conectado ao mysql.");
- }
- catch (SQLException e)
- {
- Bukkit.getConsoleSender().sendMessage("§7A conexão com o §dMySQL§7 foi negada.");
- }
- }
- }
- public static void Desconectar()
- {
- try
- {
- con.close();
- System.out.print("§cDesligar conexão com o MySQL: §c§lSucesso!");
- }
- catch (SQLException e)
- {
- System.out.print("§cDesligar conexão com o MySQL: §c§lProblema!");
- }
- }
- public static PreparedStatement getStatement(String sql)
- {
- if (jáConectado()) {
- try
- {
- return con.prepareStatement(sql);
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- return null;
- }
- public static ResultSet getResult(String sql)
- {
- if (jáConectado()) {
- try
- {
- PreparedStatement ps = getStatement(sql);
- return ps.executeQuery();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement