Advertisement
Guest User

Aide

a guest
Dec 26th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.28 KB | None | 0 0
  1. package fr.galaxie69.trygamesapi;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8.  
  9. public class Database {
  10.     private String urlBase;
  11.     private String host;
  12.     private String database;
  13.     private String username;
  14.     private String password;
  15.     private Connection connection;
  16.  
  17.     public Database(String urlBase, String host, String database, String username, String password) {
  18.         this.urlBase = urlBase;
  19.         this.host = host;
  20.         this.database = database;
  21.         this.username = username;
  22.         this.password = password;
  23.     }
  24.  
  25.     public void connection() {
  26.         if (!this.isConnected()) {
  27.             try {
  28.                 this.connection = DriverManager.getConnection(String.valueOf(this.urlBase) + this.host + "/" + this.database, this.username, this.password);
  29.                 return;
  30.             }
  31.             catch (SQLException e) {
  32.                 System.err.println("[TryGamesAPI] Connexion impossible.");
  33.                 return;
  34.             }
  35.         }
  36.     }
  37.  
  38.     public void deconnection() {
  39.         if (this.isConnected()) {
  40.             try {
  41.                 this.connection.close();
  42.                 return;
  43.             }
  44.             catch (SQLException e) {
  45.                 System.err.println("[TryGames] Deconnexion impossible");
  46.                 return;
  47.             }
  48.         }
  49.     }
  50.  
  51.     public boolean isConnected() {
  52.         try {
  53.             if (this.connection == null || this.connection.isClosed() || this.connection.isValid(5)) {
  54.                 return false;
  55.             }
  56.             return true;
  57.         }
  58.         catch (SQLException e) {
  59.             System.err.println("[TryGames] Connexion OK ?");
  60.             return false;
  61.         }
  62.     }
  63.  
  64.     public Connection getConnection() {
  65.         return this.connection;
  66.     }
  67.    
  68.    
  69.     public ResultSet getRank() {
  70.         try {
  71.             Statement statement = connection.createStatement();
  72.             ResultSet prr = statement.executeQuery("SELECT groupid FROM playersgroups WHERE uuid=+p.geUniqueId().toString()+;");
  73.             prr.next();
  74.             return prr;
  75.         } catch (SQLException e) {
  76.             System.out.println("[TryHub] Select impossible");
  77.             e.printStackTrace();
  78.         }
  79.         return null;
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement