Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.buzzfx.ffa.MySQL;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import org.bukkit.Bukkit;
- public class MySQL {
- public static String passwd = "";
- public static String database = "test";
- public static String user = "root";
- public static String host = "localhost";
- public static int port = 3306;
- public static Connection con;
- public static void connect() {
- if(!isConnect()) {
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, user, passwd);
- Bukkit.getConsoleSender().sendMessage("§7[§3FFA§7] §a MySQL enabled.");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void disconnect() {
- if(isConnect()) {
- try {
- con.close();
- Bukkit.getConsoleSender().sendMessage("§7[§3FFA§7] §a MySQL disabled.");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static boolean isConnect() {
- return con != null;
- }
- public static void createTable() {
- if(isConnect()) {
- try {
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS FFAStats (Player VARCHAR (100), UUID VARCHAR (100),Kills INT (100), Deaths INT (100)) ");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void update(String qry) {
- if(isConnect()) {
- try {
- con.createStatement().executeUpdate(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static ResultSet getResult(String qry) {
- if(isConnect()) {
- try {
- return con.createStatement().executeQuery(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement