Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.galaxie69.trygamesapi;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class Database {
- private String urlBase;
- private String host;
- private String database;
- private String username;
- private String password;
- private Connection connection;
- public Database(String urlBase, String host, String database, String username, String password) {
- this.urlBase = urlBase;
- this.host = host;
- this.database = database;
- this.username = username;
- this.password = password;
- }
- public void connection() {
- if (!this.isConnected()) {
- try {
- this.connection = DriverManager.getConnection(String.valueOf(this.urlBase) + this.host + "/" + this.database, this.username, this.password);
- return;
- }
- catch (SQLException e) {
- System.err.println("[TryGamesAPI] Connexion impossible.");
- return;
- }
- }
- }
- public void deconnection() {
- if (this.isConnected()) {
- try {
- this.connection.close();
- return;
- }
- catch (SQLException e) {
- System.err.println("[TryGames] Deconnexion impossible");
- return;
- }
- }
- }
- public boolean isConnected() {
- try {
- if (this.connection == null || this.connection.isClosed() || this.connection.isValid(5)) {
- return false;
- }
- return true;
- }
- catch (SQLException e) {
- System.err.println("[TryGames] Connexion OK ?");
- return false;
- }
- }
- public Connection getConnection() {
- return this.connection;
- }
- public ResultSet getRank() {
- try {
- Statement statement = connection.createStatement();
- ResultSet prr = statement.executeQuery("SELECT groupid FROM playersgroups WHERE uuid="+p.getUniqueId().toString());
- prr.next();
- return prr;
- } catch (SQLException e) {
- System.out.println("[TryHub] Select impossible");
- e.printStackTrace();
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement