Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.algathia.algathiaapi.utils;
- 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 fr.algathia.algathiaapi.AlgathiaAPI;
- import net.md_5.bungee.BungeeCord;
- public class SQL {
- protected static Connection conn;
- static String ip, database, userName, password;
- static int port;
- public SQL(String ip, int port, String database, String userName, String password) {
- SQL.ip = ip;
- SQL.port = port;
- SQL.database = database;
- SQL.userName = userName;
- SQL.password = password;
- connect();
- }
- private static void connect() {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- try {
- conn = DriverManager.getConnection("jdbc:mysql://" + ip + ":" + port + "/" + database, userName, password);
- System.out.println("SQL Connection work !");
- } catch (SQLException e) {
- System.out.println("SQL Connection don't work !");
- e.printStackTrace();
- if(AlgathiaAPI.isSpigot())
- Bukkit.shutdown();
- else
- BungeeCord.getInstance().stop();
- }
- }
- public static void writedata(String sql) {
- try {
- if (conn.isClosed()) {
- connect();
- }
- Statement state = conn.createStatement();
- state.executeUpdate(sql);
- state.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static ResultSet getdata(String sql) {
- ResultSet result = null;
- try {
- if (conn.isClosed()) {
- connect();
- }
- Statement state = conn.createStatement();
- result = state.executeQuery(sql);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement