From 1b57ceb42c471d8367ec04df72babb71cd5f8828 Mon Sep 17 00:00:00 2001 From: daveluy Date: Wed, 20 Dec 2023 13:47:35 +0100 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'DonjonBdB.java'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DonjonBdB.java | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/DonjonBdB.java b/DonjonBdB.java index d96889f..feed1d3 100644 --- a/DonjonBdB.java +++ b/DonjonBdB.java @@ -1,12 +1,28 @@ public class DonjonBd extends Donjon{ - public void connection(){ - Connection cnx = DriverManager.getConnection( - "jdbc:mariadb://dwarves.iut-fbleau.fr/elhaddad", - "elhaddad", "NassimPHP77550"); - try{ - Class.forName("org.mariadb.jdbc.Driver"); - }catch(ClassNotFoundException); - } + public Connection getConnection(){ + try { + try { + Class.forName("org.mariadb.jdbc.Driver"); + } catch (ClassNotFoundException e) { + System.err.println("La classe permettant la connexion au serveur SQL n'a pas été ouverte à l'exécution"); + return null; + } + cnx = DriverManager.getConnection("jdbc:mariadb://dwarves.iut-fbleau.fr/elhaddad", + "elhaddad", "NassimPHP77550"); + } catch (SQLException e) { + System.err.println("Connexion échouée"); + } + return cnx; + } + + public void Fermeture(){ + try { + cnx.close(); + } catch (SQLException e) { + System.err.println("Erreur dans la fermeture"); + } + + } } \ No newline at end of file