0

The MySQL version is 8.0.16

I modified the table character set and collation :

alter table pdrintervention character set utf8mb4 collate utf8mb4_0900_ai_ci;

At runtime I still get the Incorrect string value: '\xEF\xBF\xBD' error when importing a csv file containing the ² character.

Here is how the csv is imported ( through Spring-boot ) :

List<String> lines = FileUtils.readLines(csv, StandardCharsets.UTF_8);
Boolean intervExists = true;
Boolean dataError = false;
int i = 0;
for(String line : lines) {
    if (i > 0) {
        String[] champs = line.split(";");
        if (champs[2] == null || (champs[2]).trim().equals("")) {
            intervExists = false;
            break;
        }
        else {
            String codeArticle = champs[0];
            String designation = champs[1];
            Integer interv = Integer.parseInt(champs[2]);
            Double qteSortie = Double.parseDouble(champs[3]);
            String refos = champs[4];
            Integer idequipement = 0;
            Double pu = Double.valueOf("0");
            Double qteDmd = Double.valueOf("0");
            Double qtePosee = Double.valueOf("0");
            
            String sql = "insert into pdrintervention(code, designation, idintervention, quantitesortie, refos, idequipement, prixunitaire, quantitedemandee, quantiteposee) " +
                     "values(:codeArticle, :designation, :interv, :qteSortie, :refos, :idequipement, :pu, :qteDmd, :qtePosee)";
            Query query = entityManager.createNativeQuery(sql);
            query.setParameter("codeArticle", codeArticle);
            query.setParameter("designation", designation); // this caused the error
            query.setParameter("interv", interv);
            query.setParameter("qteSortie", qteSortie);
            query.setParameter("refos", refos);
            query.setParameter("idequipement", idequipement);
            query.setParameter("pu", pu);
            query.setParameter("qteDmd", qteDmd);
            query.setParameter("qtePosee", qtePosee);
            query.executeUpdate();
        }
    }
    i++;
}

So what is wrong ?

edit :

here is result of SHOW VARIABLES LIKE 'char%' :

character_set_client,utf8mb4
character_set_connection,utf8mb4
character_set_database,utf8mb4
character_set_filesystem,binary
character_set_results,utf8mb4
character_set_server,utf8mb4
character_set_system,utf8
character_sets_dir,D:\Wamp\bin\mysql\mysql8.0.16\share\charsets\
pheromix
  • 18,213
  • 29
  • 88
  • 158
  • Please [edit] your question to share a [mcve]. How are you *importing a csv file containing the ² character*? And is that file saved using `utf-8` encoding? – JosefZ Jan 25 '22 at 10:16
  • The import is made through Spring-boot, and the file is perhaps not in `utf-8` encoding – pheromix Jan 25 '22 at 10:17
  • Please **[edit]** your question to provide a [mcve]. – JosefZ Jan 25 '22 at 10:18
  • Looks like a problem with connection character set. Check `SHOW VARIABLES LIKE 'char%';` output for the connection. See Reference Manual, `SET NAMES` statement description. – Akina Jan 25 '22 at 10:51
  • @Akina here is the connect string : `spring.datasource.url = jdbc:mysql://localhost:3306/gmao?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC` ; so what should be changed in here ? – pheromix Jan 25 '22 at 10:52
  • Please check what I have asked, not one you have imagined. Execute shown statement, add the output to your question. – Akina Jan 25 '22 at 10:55

0 Answers0