From 26c4272163bb0b77f1e01eeceb0d0087d745d5d3 Mon Sep 17 00:00:00 2001 From: "clementine.desrucques" Date: Wed, 20 Oct 2021 11:56:07 +0200 Subject: [PATCH] --- src/java/bdd/PompierMySql.java | 41 ++++++++++++++++++++++ src/java/com/test/beans/Pompier.java | 28 +++++++++++---- src/java/com/test/forms/AuthentifForm.java | 8 +++-- web/WEB-INF/ChefCaserneJSP.jsp | 3 +- 4 files changed, 70 insertions(+), 10 deletions(-) diff --git a/src/java/bdd/PompierMySql.java b/src/java/bdd/PompierMySql.java index 013398b..8113ded 100644 --- a/src/java/bdd/PompierMySql.java +++ b/src/java/bdd/PompierMySql.java @@ -32,6 +32,47 @@ public class PompierMySql { "minda"); // mot de passe ClientMysql() { } + /** + * Recherche de tous les clients + * @return collection de clients + */ + public ArrayList readAll() { + ArrayList lesPompiers = new ArrayList<>(); + + try { + Statement stmt = theConnection.createStatement(); + ResultSet resultQ = null; + resultQ = stmt.executeQuery("SELECT * FROM pompier"); + while (resultQ.next()) { + unPompier = new Pompier(resultQ.getInt("id"), + resultQ.getInt("idCaserne"), + resultQ.getString("nom"), + resultQ.getString("prenom"), + resultQ.getInt("statut"), + resultQ.getString("mail"), + resultQ.getString("login"), + resultQ.getString("mdp"), + resultQ.getInt("adrNo"), + resultQ.getString("adrRue"), + resultQ.getString("adrCP"), + resultQ.getString("adrVille"), + resultQ.getInt("grade"), + resultQ.getString("commentaire") + ); + lesPompiers.add(unPompier); + } + resultQ.close(); + stmt.close(); + //theConnection.close(); + } catch (SQLException ex) { + System.out.println("SQLException : " + ex.getMessage()); + System.out.println("SQLState : " + ex.getSQLState()); + System.out.println("Code erreur : " + ex.getErrorCode()); + } + + return lesPompiers; + } + /** * Creation du pompier passé en paramètre dans la table pompier * Requête non préparée diff --git a/src/java/com/test/beans/Pompier.java b/src/java/com/test/beans/Pompier.java index 6771412..bcbedb6 100644 --- a/src/java/com/test/beans/Pompier.java +++ b/src/java/com/test/beans/Pompier.java @@ -25,13 +25,14 @@ public class Pompier { private String adrCP; private String adrVille; private int grade; + private String commentaire; - public Pompier(int id, int idCaserne, String nom, String prenom, int statut, String mail, String login, String mdp, int adrNo, String adrRue, String adrCP, String adrVille, int grade) { - this(idCaserne, nom, prenom, statut, mail, login, mdp, adrNo, adrRue, adrCP, adrVille, grade); + public Pompier(int id, int idCaserne, String nom, String prenom, int statut, String mail, String login, String mdp, int adrNo, String adrRue, String adrCP, String adrVille, int grade, String commentaire) { + this(idCaserne, nom, prenom, statut, mail, login, mdp, adrNo, adrRue, adrCP, adrVille, grade, commentaire); this.id = id; } - - public Pompier(int idCaserne, String nom, String prenom, int statut, String mail, String login, String mdp, int adrNo, String adrRue, String adrCP, String adrVille, int grade) { + + public Pompier(int idCaserne, String nom, String prenom, int statut, String mail, String login, String mdp, int adrNo, String adrRue, String adrCP, String adrVille, int grade, String commentaire) { this.idCaserne = idCaserne; this.nom = nom; this.prenom = prenom; @@ -44,9 +45,9 @@ public class Pompier { this.adrCP = adrCP; this.adrVille = adrVille; this.grade = grade; + this.commentaire = commentaire; } - public int getId() { return id; } @@ -151,9 +152,17 @@ public class Pompier { this.grade = grade; } + public String getCommentaire() { + return commentaire; + } + + public void setCommentaire(String commentaire) { + this.commentaire = commentaire; + } + @Override public int hashCode() { - int hash = 7; + int hash = 3; hash = 29 * hash + this.id; hash = 29 * hash + this.idCaserne; hash = 29 * hash + Objects.hashCode(this.nom); @@ -167,6 +176,7 @@ public class Pompier { hash = 29 * hash + Objects.hashCode(this.adrCP); hash = 29 * hash + Objects.hashCode(this.adrVille); hash = 29 * hash + this.grade; + hash = 29 * hash + Objects.hashCode(this.commentaire); return hash; } @@ -221,13 +231,17 @@ public class Pompier { if (!Objects.equals(this.adrVille, other.adrVille)) { return false; } + if (!Objects.equals(this.commentaire, other.commentaire)) { + return false; + } return true; } @Override public String toString() { - return "Pompier{" + "id=" + id + ", idCaserne=" + idCaserne + ", nom=" + nom + ", prenom=" + prenom + ", statut=" + statut + ", mail=" + mail + ", login=" + login + ", mdp=" + mdp + ", adrNo=" + adrNo + ", adrRue=" + adrRue + ", adrCP=" + adrCP + ", adrVille=" + adrVille + ", grade=" + grade + '}'; + return "Pompier{" + "id=" + id + ", idCaserne=" + idCaserne + ", nom=" + nom + ", prenom=" + prenom + ", statut=" + statut + ", mail=" + mail + ", login=" + login + ", mdp=" + mdp + ", adrNo=" + adrNo + ", adrRue=" + adrRue + ", adrCP=" + adrCP + ", adrVille=" + adrVille + ", grade=" + grade + ", commentaire=" + commentaire + '}'; } + } diff --git a/src/java/com/test/forms/AuthentifForm.java b/src/java/com/test/forms/AuthentifForm.java index 21a8e5c..61bec19 100644 --- a/src/java/com/test/forms/AuthentifForm.java +++ b/src/java/com/test/forms/AuthentifForm.java @@ -42,10 +42,14 @@ public class AuthentifForm { /* Comparaison entre l'utilisateur admin et un utilisateur créé avec le pseudo et le mdp saisi */ // UserP ChefCaserne = new UserP("Michel", "mRANN"); - UserP userSaisi = new UserP( request.getParameter("ztPseudo"), + Statement stmt = theConnection.createStatement(); + ResultSet resultQ = null; + resultQ = stmt.executeQuery("SELECT * FROM pompier WHERE login=); + boolean isChef=false; + Pompier userSaisi = new Pompier( request.getParameter("ztPseudo"), request.getParameter("ztMDP")); if(request.getParameter("ztPseudo").equals(request)){ - boolean isChef = userSaisi; + isChef=true; } // Mise à jour de l'attribut resultat setResultat(isChef ? "Vous êtes chef de caserne" : "Vous n'êtes pas chef de caserne"); diff --git a/web/WEB-INF/ChefCaserneJSP.jsp b/web/WEB-INF/ChefCaserneJSP.jsp index 9625ebf..effb6d5 100644 --- a/web/WEB-INF/ChefCaserneJSP.jsp +++ b/web/WEB-INF/ChefCaserneJSP.jsp @@ -5,6 +5,7 @@ --%> <%@include file = "jspf/enteteJSPF.jspf" %> <%@page contentType="text/html" pageEncoding="UTF-8"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> @@ -48,7 +49,7 @@ - +