Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.eligames.api.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 Connection connection;
- public static String username;
- public static String password;
- public static String database;
- public static String host;
- public static String port;
- public static String tablePlayers = "players";
- public static void connect() {
- if (!isConnected()) {
- try {
- connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username,
- password);
- Bukkit.getConsoleSender().sendMessage("�a[�bEliBeta�a] �aConnexion MySQL effectu�e !");
- } catch (SQLException e) {
- e.printStackTrace();
- Bukkit.getConsoleSender().sendMessage("�a[�bEliBeta�a] �cConnexion impossible !");
- }
- }
- }
- public static void close() {
- if (isConnected()) {
- try {
- connection.close();
- Bukkit.getConsoleSender().sendMessage("�a[�bEliGames�a] �6Connexion MySQL ferm�e !");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static boolean isConnected() {
- return connection != null;
- }
- public static void update(String qry) {
- if (isConnected()) {
- try {
- connection.createStatement().executeUpdate(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static ResultSet getResult(String qry) {
- if (isConnected()) {
- try {
- return connection.createStatement().executeQuery(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement