package testeurfonction; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.time.LocalDate; import java.util.ArrayList; public class TesteurFonction { public static void main(String[] args) throws Exception { String date = JJMMAAAA(LocalDate.now()); ArrayList result = new ArrayList<>(); try { //OUVERTURE DU FICHIER FileReader fr = new FileReader(new File("/home/rkl/Bureau/examen_code_" + date + ".csv")); BufferedReader br = new BufferedReader(fr); // LECTURE DES LIGNES DU FICHIER // ENREGISTREMENT DES LIGNE DANS UNE COLLECTION ARRAYLIST for(String line = br.readLine(); line != null; line = br.readLine()) result.add(line); // FERMETURE DU FICHIER EN LECTURE br.close(); fr.close(); // POUR CHAQUE LIGNE EN EVITANT L'ENTÊTE // RECUPÉRER LES DONNEES for(int i = 1; i < result.size(); i++){ String ligne = result.get(i); String champs[] = ligne.split(","); if(champs.length != 3){ throw new Exception("Erreur fichier : il doit y avoir que 3 colonnes."); } String NEPH = champs[0]; int RESULTAT = Integer.parseInt(champs[1]) + 1; int NB_REPONSES_CORRECTES = Integer.parseInt(champs[2]); // CREATION DES REQUETES SQL String requeteSQL_CLIENT = "UPDATE CLIENT SET ETAT_PIC=" + RESULTAT + "WHERE NEPH = " + NEPH; String requeteSQL_RESULTAT = ""; // CONNEXION A LA BASE DE DONNEE // EXECUTION DE LA REQUETE SQL POUR METTRE A JOUR LA BASE DE DONNEE System.out.println(ligne); } } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } private static String JJMMAAAA(LocalDate d){ StringBuilder sb = new StringBuilder(); String JJ, MM; JJ = "0" + d.getDayOfMonth(); MM = "0" + d.getMonthValue(); JJ = JJ.substring(JJ.length() - 2); MM = MM.substring(JJ.length() - 2); sb.append(JJ); sb.append(MM); sb.append(d.getYear()); return sb.toString(); } }