Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Connector {
- private static Connection connection; //permet de récupérer la connexion
- public static String //ne pas toucher
- url_base = "jdbc:mysql://";
- public static Connection getConnection(){
- return connection;
- }
- public static boolean isConnected(){ //vérifier si la connexion est établie
- try {
- if((connection == null) || (connection.isClosed())){
- return false;
- }else{
- return true;
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- public static void connect(Practice practice){
- if(!isConnected()){
- try {
- connection = DriverManager.getConnection(url_base+practice.sqlIdentifiers.getHost()+"/"+practice.sqlIdentifiers.getDtb(), practice.sqlIdentifiers.getUser(), practice.sqlIdentifiers.getPass()); //remplacer getUser par ton utilsateur et getpass par ton password
- System.out.println("Connexion base de données réussite.");
- } catch (SQLException e) {
- Practice.instance.getLogger().severe("[URGENT] La connexion à la base de données est impossible. Le serveur ne peut pas démarrer.");
- e.printStackTrace();
- Bukkit.getServer().shutdown();
- }
- }
- }
- public static void disconnect(){ // se déconnecter
- if(isConnected()){
- try {
- connection.close();
- System.out.println("Déconnexion à la base de donnée réussite.");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement