diff --git a/sae/WEB-INF/src/modele/Abonnement.java b/sae/WEB-INF/src/modele/Abonnement.java new file mode 100644 index 0000000000000000000000000000000000000000..43788118275ae962e2bb4d66d4997608ddc62a1d --- /dev/null +++ b/sae/WEB-INF/src/modele/Abonnement.java @@ -0,0 +1,51 @@ +package modele; + +import java.time.LocalDate; + +public class Abonnement { + private int idUtilisateur; + private int idFil; + private LocalDate dateAbonnement; + + public Abonnement() { + } + + public Abonnement(int idUtilisateur, int idFil, LocalDate dateAbonnement) { + this.idUtilisateur = idUtilisateur; + this.idFil = idFil; + this.dateAbonnement = dateAbonnement; + } + + public int getIdUtilisateur() { + return idUtilisateur; + } + + public void setIdUtilisateur(int idUtilisateur) { + this.idUtilisateur = idUtilisateur; + } + + public int getIdFil() { + return idFil; + } + + public void setIdFil(int idFil) { + this.idFil = idFil; + } + + public LocalDate getDateAbonnement() { + return dateAbonnement; + } + + public void setDateAbonnement(LocalDate dateAbonnement) { + this.dateAbonnement = dateAbonnement; + } + + @Override + public String toString() { + return "Abonnement{" + + "idUtilisateur=" + idUtilisateur + + ", idFil=" + idFil + + ", dateAbonnement=" + dateAbonnement + + '}'; + } +} diff --git a/sae/WEB-INF/src/modele/AbonnementDao.java b/sae/WEB-INF/src/modele/AbonnementDao.java new file mode 100644 index 0000000000000000000000000000000000000000..b34a26237099ac7c9de636f8e3bd761a86790433 --- /dev/null +++ b/sae/WEB-INF/src/modele/AbonnementDao.java @@ -0,0 +1,67 @@ +package modele; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.List; +import java.util.ArrayList; + +public class AbonnementDao { + + public Abonnement findAbonnement(int idUtilisateur, int idFil) { + Abonnement abonnement = new Abonnement(); + try(Connection con = DS.instance.getConnection()) { + PreparedStatement ps = con.prepareStatement("SELECT * FROM abonnement WHERE idUtilisateur = ? AND idFil = ?"); + ps.setInt(1, idUtilisateur); + ps.setInt(2, idFil); + ResultSet rs = ps.executeQuery(); + if (rs.next()) { + abonnement.setIdUtilisateur(rs.getInt("idUtilisateur")); + abonnement.setIdFil(rs.getInt("idFil")); + abonnement.setDateAbonnement(rs.getDate("dateAbonnement").toLocalDate()); + } else { + System.out.println("Abonnement inexistant"); + } + } catch (Exception e) { + System.out.println(e.getMessage()); + } + return abonnement; + } + + public List<Abonnement> findAll() { + List<Abonnement> abonnements = new ArrayList<>(); + try(Connection con = DS.instance.getConnection()) { + PreparedStatement ps = con.prepareStatement("SELECT * FROM abonnement"); + ResultSet rs = ps.executeQuery(); + while (rs.next()) { + Abonnement abonnement = new Abonnement(); + abonnement.setIdUtilisateur(rs.getInt("idUtilisateur")); + abonnement.setIdFil(rs.getInt("idFil")); + abonnement.setDateAbonnement(rs.getDate("dateAbonnement").toLocalDate()); + abonnements.add(abonnement); + } + } catch (Exception e) { + System.out.println(e.getMessage()); + } + return abonnements; + } + + public List<Abonnement> findAbonnements(int idUtilisateur) { + List<Abonnement> abonnements = new ArrayList<>(); + try(Connection con = DS.instance.getConnection()) { + PreparedStatement ps = con.prepareStatement("SELECT * FROM abonnement WHERE idUtilisateur = ?"); + ps.setInt(1, idUtilisateur); + ResultSet rs = ps.executeQuery(); + while (rs.next()) { + Abonnement abonnement = new Abonnement(); + abonnement.setIdUtilisateur(rs.getInt("idUtilisateur")); + abonnement.setIdFil(rs.getInt("idFil")); + abonnement.setDateAbonnement(rs.getDate("dateAbonnement").toLocalDate()); + abonnements.add(abonnement); + } + } catch (Exception e) { + System.out.println(e.getMessage()); + } + return abonnements; + } +} diff --git a/sae/WEB-INF/src/modele/DAO.java b/sae/WEB-INF/src/modele/DAO.java deleted file mode 100644 index aa8d5671554ce66b7487c29011d128caba5177f1..0000000000000000000000000000000000000000 --- a/sae/WEB-INF/src/modele/DAO.java +++ /dev/null @@ -1,24 +0,0 @@ -package modele; - -import java.util.ArrayList; -import java.util.List; - -public class DAO { - List<String> list; - - public DAO() { - list = new ArrayList<String>(); - for (int i = 0; i < 10; i++) { - list.add("Element " + i); - } - } - - public List<String> findAll() { - return list; - } - - public String findById(int n) { - int index = n % list.size(); - return list.get(index); - } -} diff --git a/sae/WEB-INF/src/modele/Joueur.java b/sae/WEB-INF/src/modele/Joueur.java deleted file mode 100644 index 3139bf499f1855d564b18d4263ec086e85992751..0000000000000000000000000000000000000000 --- a/sae/WEB-INF/src/modele/Joueur.java +++ /dev/null @@ -1,56 +0,0 @@ -package modele; - -public class Joueur { - private int jno; - private String pseudo; - private String email; - private String pwd; - private int elo; - - public Joueur() { - } - - public Joueur(int jno, String pseudo, String email, String pwd, int elo) { - this.jno = jno; - this.pseudo = pseudo; - this.email = email; - this.pwd = pwd; - this.elo = elo; - } - - public int getJno() { - return jno; - } - public void setJno(int jno) { - this.jno = jno; - } - public String getPseudo() { - return pseudo; - } - public void setPseudo(String pseudo) { - this.pseudo = pseudo; - } - public String getEmail() { - return email; - } - public void setEmail(String email) { - this.email = email; - } - public String getPwd() { - return pwd; - } - public void setPwd(String pwd) { - this.pwd = pwd; - } - public int getElo() { - return elo; - } - public void setElo(int elo) { - this.elo = elo; - } - - @Override - public String toString() { - return "Joueur [elo=" + elo + ", email=" + email + ", jno=" + jno + ", pseudo=" + pseudo + "]"; - } -} \ No newline at end of file diff --git a/sae/WEB-INF/src/modele/JoueurDao.java b/sae/WEB-INF/src/modele/JoueurDao.java deleted file mode 100644 index 4a53f4ac44a244d63bb407ab8eceb95055c50c5f..0000000000000000000000000000000000000000 --- a/sae/WEB-INF/src/modele/JoueurDao.java +++ /dev/null @@ -1,10 +0,0 @@ -package modele; - -import java.util.List; - -public interface JoueurDao { - public Joueur findById(int id); - public void create(Joueur joueur); - public List<Joueur> findAll(); - public void delete(int id); -} diff --git a/sae/WEB-INF/src/modele/JoueurJdbcDao.java b/sae/WEB-INF/src/modele/JoueurJdbcDao.java deleted file mode 100644 index 8404b9d9bc8646b86a9196efd40c5863456bf729..0000000000000000000000000000000000000000 --- a/sae/WEB-INF/src/modele/JoueurJdbcDao.java +++ /dev/null @@ -1,74 +0,0 @@ -package modele; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.util.ArrayList; -import java.util.List; - -public class JoueurJdbcDao implements JoueurDao { - public Joueur findById(int id) { - Joueur j = new Joueur(); - try (Connection con = DS.instance.getConnection()) { - PreparedStatement ps = con.prepareStatement("SELECT * FROM joueur WHERE jno = ?"); - ps.setInt(1, id); - ResultSet rs = ps.executeQuery(); - if (rs.next()) { - j.setJno(rs.getInt("jno")); - j.setPseudo(rs.getString("pseudo")); - j.setEmail(rs.getString("email")); - j.setPwd(rs.getString("pwd")); - j.setElo(rs.getInt("elo")); - } else { - System.out.println("Joueur inexistant"); - } - } catch (Exception e) { - System.out.println(e.getMessage()); - } - return j; - } - - public void create(Joueur joueur) { - try (Connection con = DS.instance.getConnection()) { - PreparedStatement pstmt = con.prepareStatement("INSERT INTO joueur (jno, pseudo, email, pwd, elo) VALUES (?, ?, ?, ?, ?)"); - pstmt.setInt(1, joueur.getJno()); - pstmt.setString(2, joueur.getPseudo()); - pstmt.setString(3, joueur.getEmail()); - pstmt.setString(4, joueur.getPwd()); - pstmt.setInt(5, joueur.getElo()); - pstmt.executeUpdate(); - } catch (Exception e) { - System.err.println(e.getMessage()); - } - } - - public List<Joueur> findAll() { - List<Joueur> joueurs = new ArrayList<>(); - try (Connection con = DS.instance.getConnection()) { - PreparedStatement ps = con.prepareStatement("SELECT * FROM joueur"); - ResultSet rs = ps.executeQuery(); - while (rs.next()) { - Joueur j = new Joueur(); - j.setJno(rs.getInt("jno")); - j.setPseudo(rs.getString("pseudo")); - j.setEmail(rs.getString("email")); - j.setPwd(rs.getString("pwd")); - j.setElo(rs.getInt("elo")); - joueurs.add(j); - } - } catch (Exception e) { - System.out.println(e.getMessage()); - } - return joueurs; - } - - public void delete(int id) { - try (Connection con = DS.instance.getConnection()) { - PreparedStatement ps = con.prepareStatement("DELETE FROM joueur WHERE jno = ?"); - ps.setInt(1, id); - ps.executeUpdate(); - } catch (Exception e) { - System.out.println(e.getMessage()); - } - } -} diff --git a/sae/WEB-INF/src/modele/Message.java b/sae/WEB-INF/src/modele/Message.java new file mode 100644 index 0000000000000000000000000000000000000000..a6a68e317ea534ea3be27187980b296c32433e41 --- /dev/null +++ b/sae/WEB-INF/src/modele/Message.java @@ -0,0 +1,67 @@ +package modele; + +import java.time.LocalDate; + +public class Message { + private int id; + private String contenu; + private LocalDate datePublication; + private int idFil; + private int idAuteur; + + public Message() { + } + + public Message(int id, String contenu, LocalDate datePublication, int idFil, int idAuteur) { + this.id = id; + this.contenu = contenu; + this.datePublication = datePublication; + this.idFil = idFil; + this.idAuteur = idAuteur; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getContenu() { + return contenu; + } + + public void setContenu(String contenu) { + this.contenu = contenu; + } + + public LocalDate getDatePublication() { + return datePublication; + } + + public void setDatePublication(LocalDate datePublication) { + this.datePublication = datePublication; + } + + public int getIdFil() { + return idFil; + } + + public void setIdFil(int idFil) { + this.idFil = idFil; + } + + public int getIdAuteur() { + return idAuteur; + } + + public void setIdAuteur(int idAuteur) { + this.idAuteur = idAuteur; + } + + @Override + public String toString() { + return "Message{" + "id=" + id + ", contenu=" + contenu + ", datePublication=" + datePublication + ", idFil=" + idFil + ", idAuteur=" + idAuteur + '}'; + } +} diff --git a/sae/WEB-INF/src/modele/MessageDao.java b/sae/WEB-INF/src/modele/MessageDao.java new file mode 100644 index 0000000000000000000000000000000000000000..1f024be3b3e66947e36afbb92cf47adb4c238e01 --- /dev/null +++ b/sae/WEB-INF/src/modele/MessageDao.java @@ -0,0 +1,72 @@ +package modele; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.List; +import java.util.ArrayList; + +public class MessageDao { + + public Message findMessage(int id) { + Message message = new Message(); + try(Connection con = DS.instance.getConnection()) { + PreparedStatement ps = con.prepareStatement("SELECT * FROM message WHERE id = ?"); + ps.setInt(1, id); + ResultSet rs = ps.executeQuery(); + if (rs.next()) { + message.setId(rs.getInt("id")); + message.setContenu(rs.getString("contenu")); + message.setDatePublication(rs.getDate("datePublication").toLocalDate()); + message.setIdFil(rs.getInt("idFil")); + message.setIdAuteur(rs.getInt("idAuteur")); + } else { + System.out.println("Message inexistant"); + } + } catch (Exception e) { + System.out.println(e.getMessage()); + } + return message; + } + + public List<Message> findAll() { + List<Message> messages = new ArrayList<>(); + try(Connection con = DS.instance.getConnection()) { + PreparedStatement ps = con.prepareStatement("SELECT * FROM message"); + ResultSet rs = ps.executeQuery(); + while (rs.next()) { + Message message = new Message(); + message.setId(rs.getInt("id")); + message.setContenu(rs.getString("contenu")); + message.setDatePublication(rs.getDate("datePublication").toLocalDate()); + message.setIdFil(rs.getInt("idFil")); + message.setIdAuteur(rs.getInt("idAuteur")); + messages.add(message); + } + } catch (Exception e) { + System.out.println(e.getMessage()); + } + return messages; + } + + public List<Message> findMessages(int idFil) { + List<Message> messages = new ArrayList<>(); + try(Connection con = DS.instance.getConnection()) { + PreparedStatement ps = con.prepareStatement("SELECT * FROM message WHERE idFil = ?"); + ps.setInt(1, idFil); + ResultSet rs = ps.executeQuery(); + while (rs.next()) { + Message message = new Message(); + message.setId(rs.getInt("id")); + message.setContenu(rs.getString("contenu")); + message.setDatePublication(rs.getDate("datePublication").toLocalDate()); + message.setIdFil(rs.getInt("idFil")); + message.setIdAuteur(rs.getInt("idAuteur")); + messages.add(message); + } + } catch (Exception e) { + System.out.println(e.getMessage()); + } + return messages; + } +} diff --git a/sae/WEB-INF/src/modele/Partie.java b/sae/WEB-INF/src/modele/Partie.java deleted file mode 100644 index aebc0cf897dca90481f9b90cd4e42df1c6d766ba..0000000000000000000000000000000000000000 --- a/sae/WEB-INF/src/modele/Partie.java +++ /dev/null @@ -1,62 +0,0 @@ -package modele; - -import java.time.LocalDate; - -public class Partie { - int pno; - int jno1; - int jno2; - LocalDate date; - String statut; - int temps; - int gagnant; - - public int getPno() { - return pno; - } - public void setPno(int pno) { - this.pno = pno; - } - public int getJno1() { - return jno1; - } - public void setJno1(int jno1) { - this.jno1 = jno1; - } - public int getJno2() { - return jno2; - } - public void setJno2(int jno2) { - this.jno2 = jno2; - } - public LocalDate getDate() { - return date; - } - public void setDate(LocalDate date) { - this.date = date; - } - public String getStatut() { - return statut; - } - public void setStatut(String statut) { - this.statut = statut; - } - public int getTemps() { - return temps; - } - public void setTemps(int temps) { - this.temps = temps; - } - public int getGagnant() { - return gagnant; - } - public void setGagnant(int gagnant) { - this.gagnant = gagnant; - } - - @Override - public String toString() { - return "Partie [date=" + date + ", gagnant=" + gagnant + ", jno1=" + jno1 + ", jno2=" + jno2 + ", pno=" + pno - + ", statut=" + statut + ", temps=" + temps + "]"; - } -} diff --git a/sae/WEB-INF/src/modele/PartieDAO.java b/sae/WEB-INF/src/modele/PartieDAO.java deleted file mode 100644 index a7c475b0089b8f7aef9f1d8bec9c98920d0510d7..0000000000000000000000000000000000000000 --- a/sae/WEB-INF/src/modele/PartieDAO.java +++ /dev/null @@ -1,100 +0,0 @@ -package modele; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.time.LocalDate; -import java.util.List; -import java.util.ArrayList; - -public class PartieDAO { - public Partie findPartie(int pno) { - Partie partie = new Partie(); - try(Connection con = DS.instance.getConnection()) { - PreparedStatement ps = con.prepareStatement("SELECT * FROM partie WHERE pno = ?"); - ps.setInt(1, pno); - ResultSet rs = ps.executeQuery(); - if (rs.next()) { - partie.setPno(rs.getInt("pno")); - partie.setJno1(rs.getInt("jno1")); - partie.setJno2(rs.getInt("jno2")); - partie.setDate(rs.getDate("date").toLocalDate()); - partie.setStatut(rs.getString("statut")); - partie.setTemps(rs.getInt("temps")); - partie.setGagnant(rs.getInt("gagnant")); - } else { - System.out.println("Partie inexistante"); - } - } catch (Exception e) { - System.out.println(e.getMessage()); - } - return partie; - } - - public List<Partie> findAll() { - List<Partie> parties = new ArrayList<>(); - try(Connection con = DS.instance.getConnection()) { - PreparedStatement ps = con.prepareStatement("SELECT * FROM partie"); - ResultSet rs = ps.executeQuery(); - while (rs.next()) { - Partie partie = new Partie(); - partie.setPno(rs.getInt("pno")); - partie.setJno1(rs.getInt("jno1")); - partie.setJno2(rs.getInt("jno2")); - partie.setDate(rs.getDate("date").toLocalDate()); - partie.setStatut(rs.getString("statut")); - partie.setTemps(rs.getInt("temps")); - partie.setGagnant(rs.getInt("gagnant")); - parties.add(partie); - } - } catch (Exception e) { - System.out.println(e.getMessage()); - } - return parties; - } - - public Joueur[] findPlayers(int pno) { - Joueur[] joueurs = new Joueur[2]; - JoueurDao jdao = new JoueurJdbcDao(); - try(Connection con = DS.instance.getConnection()) { - PreparedStatement ps = con.prepareStatement("SELECT * FROM partie WHERE pno = ?"); - ps.setInt(1, pno); - ResultSet rs = ps.executeQuery(); - if (rs.next()) { - Joueur j1 = jdao.findById(rs.getInt("jno1")); - joueurs[0] = j1; - Joueur j2 = jdao.findById(rs.getInt("jno2")); - joueurs[1] = j2; - } else { - System.out.println("Partie inexistante"); - } - } catch (Exception e) { - System.out.println(e.getMessage()); - } - return joueurs; - } - - public void modifierPartie(int pno, int jno1, int jno2, String date, String statut) { - try(Connection con = DS.instance.getConnection()) { - PreparedStatement ps = con.prepareStatement("UPDATE partie SET jno1 = ?, jno2 = ?, date = ?, statut = ? WHERE pno = ?"); - ps.setInt(1, jno1); - ps.setInt(2, jno2); - ps.setDate(3, java.sql.Date.valueOf(date)); - ps.setString(4, statut); - ps.setInt(5, pno); - ps.executeUpdate(); - } catch (Exception e) { - System.out.println(e.getMessage()); - } - } - - public void delete(int pno) { - try(Connection con = DS.instance.getConnection()) { - PreparedStatement ps = con.prepareStatement("DELETE FROM partie WHERE pno = ?"); - ps.setInt(1, pno); - ps.executeUpdate(); - } catch (Exception e) { - System.out.println(e.getMessage()); - } - } -} diff --git a/sae/WEB-INF/src/modele/SupprimerPartie.java b/sae/WEB-INF/src/modele/SupprimerPartie.java deleted file mode 100644 index 4a761946d629e5ca6109b3d651262565675b4e18..0000000000000000000000000000000000000000 --- a/sae/WEB-INF/src/modele/SupprimerPartie.java +++ /dev/null @@ -1,21 +0,0 @@ -package modele; - -import java.io.IOException; - -import jakarta.servlet.ServletException; -import jakarta.servlet.ServletRequest; -import jakarta.servlet.ServletResponse; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; - -@WebServlet("/SupprimerPartie") -public class SupprimerPartie extends HttpServlet { - @Override - public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { - int pno = Integer.parseInt(req.getParameter("pno")); - PartieDAO pdao = new PartieDAO(); - pdao.delete(pno); - } -} diff --git a/sae/WEB-INF/src/modele/Utilisateur.java b/sae/WEB-INF/src/modele/Utilisateur.java new file mode 100644 index 0000000000000000000000000000000000000000..60fb72588649b7331121221975bd584f415208d9 --- /dev/null +++ b/sae/WEB-INF/src/modele/Utilisateur.java @@ -0,0 +1,67 @@ +package modele; + +import java.time.LocalDate; + +public class Utilisateur { + private int id; + private String nom; + private String email; + private String motDePasse; // HASH + private LocalDate dateInscription; + + public Utilisateur() { + } + + public Utilisateur(int id, String nom, String email, String motDePasse, LocalDate dateInscription) { + this.id = id; + this.nom = nom; + this.email = email; + this.motDePasse = motDePasse; + this.dateInscription = dateInscription; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getNom() { + return nom; + } + + public void setNom(String nom) { + this.nom = nom; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getMotDePasse() { + return motDePasse; + } + + public void setMotDePasse(String motDePasse) { + this.motDePasse = motDePasse; + } + + public LocalDate getDateInscription() { + return dateInscription; + } + + public void setDateInscription(LocalDate dateInscription) { + this.dateInscription = dateInscription; + } + + @Override + public String toString() { + return "Utilisateur [dateInscription=" + dateInscription + ", email=" + email + ", id=" + id + ", nom=" + nom + "]"; + } +} diff --git a/sae/WEB-INF/src/modele/UtilisateurDao.java b/sae/WEB-INF/src/modele/UtilisateurDao.java new file mode 100644 index 0000000000000000000000000000000000000000..60f1d67d17187915d2d65d3d83c268076cd85238 --- /dev/null +++ b/sae/WEB-INF/src/modele/UtilisateurDao.java @@ -0,0 +1,87 @@ +package modele; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; + +public class UtilisateurDao { + + public Utilisateur findUtilisateur(int id) { + Utilisateur utilisateur = new Utilisateur(); + try(Connection con = DS.instance.getConnection()) { + PreparedStatement ps = con.prepareStatement("SELECT * FROM utilisateur WHERE id = ?"); + ps.setInt(1, id); + ResultSet rs = ps.executeQuery(); + if (rs.next()) { + utilisateur.setId(rs.getInt("id")); + utilisateur.setNom(rs.getString("nom")); + utilisateur.setEmail(rs.getString("email")); + utilisateur.setMotDePasse(rs.getString("motDePasse")); + utilisateur.setDateInscription(rs.getDate("dateInscription").toLocalDate()); + } else { + System.out.println("Utilisateur inexistant"); + } + } catch (Exception e) { + System.out.println(e.getMessage()); + } + return utilisateur; + } + + public Utilisateur findUtilisateur(String email, String motDePasse) { + Utilisateur utilisateur = new Utilisateur(); + try(Connection con = DS.instance.getConnection()) { + PreparedStatement ps = con.prepareStatement("SELECT * FROM utilisateur WHERE email = ? AND motDePasse = ?"); + ps.setString(1, email); + ps.setString(2, motDePasse); + ResultSet rs = ps.executeQuery(); + if (rs.next()) { + utilisateur.setId(rs.getInt("id")); + utilisateur.setNom(rs.getString("nom")); + utilisateur.setEmail(rs.getString("email")); + utilisateur.setMotDePasse(rs.getString("motDePasse")); + utilisateur.setDateInscription(rs.getDate("dateInscription").toLocalDate()); + } else { + System.out.println("Utilisateur inexistant"); + } + } catch (Exception e) { + System.out.println(e.getMessage()); + } + return utilisateur; + } + + public void delete(int id) { + try(Connection con = DS.instance.getConnection()) { + PreparedStatement ps = con.prepareStatement("DELETE FROM utilisateur WHERE id = ?"); + ps.setInt(1, id); + ps.executeUpdate(); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } + + public void update(Utilisateur utilisateur) { + try(Connection con = DS.instance.getConnection()) { + PreparedStatement ps = con.prepareStatement("UPDATE utilisateur SET nom = ?, email = ?, motDePasse = ? WHERE id = ?"); + ps.setString(1, utilisateur.getNom()); + ps.setString(2, utilisateur.getEmail()); + ps.setString(3, utilisateur.getMotDePasse()); + ps.setInt(4, utilisateur.getId()); + ps.executeUpdate(); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } + + public void insert(Utilisateur utilisateur) { + try(Connection con = DS.instance.getConnection()) { + PreparedStatement ps = con.prepareStatement("INSERT INTO utilisateur (nom, email, motDePasse, dateInscription) VALUES (?, ?, ?, ?)"); + ps.setString(1, utilisateur.getNom()); + ps.setString(2, utilisateur.getEmail()); + ps.setString(3, utilisateur.getMotDePasse()); + ps.setDate(4, java.sql.Date.valueOf(utilisateur.getDateInscription())); + ps.executeUpdate(); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } +}