/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bdd;

import com.mysql.cj.xdevapi.Client;
import com.test.beans.Pompier;
import com.test.forms.MD5;
import jakarta.servlet.http.HttpServletRequest;
import java.net.http.HttpRequest;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author thomas.millot
 */
public class PompierMysql {

    private Connection theConnection;
    private Pompier unPompier;

    public PompierMysql() {
        theConnection = Connexion.getConnect("localhost", "sdis29", "admin", "minda");
    }

    public boolean readPompier(HttpServletRequest request) {
        boolean reponse = false;
        Statement stmt;
        String userSaisi = request.getParameter("ztPseudo");
        String mdpSaisi = request.getParameter("ztMDP");
        String mdpChiffre = MD5.encode(mdpSaisi);
        System.out.println("userSaisi : "+ userSaisi);
        System.out.println("mdpSaisi : "+ mdpChiffre);
        try {
            System.out.println("Select * FROM pompier WHERE login = '"+userSaisi+"' AND mdp = '"+mdpChiffre+"';");
            stmt = theConnection.createStatement();
            ResultSet resultQ = null;
            resultQ = stmt.executeQuery("Select * FROM pompier WHERE login = '"+userSaisi+"' AND mdp = '"+mdpChiffre+"';");
            reponse = resultQ.next();            
        } catch (SQLException ex) {
            Logger.getLogger(PompierMysql.class.getName()).log(Level.SEVERE, null, ex);
        }

        return reponse;
    }

}
