Remove quotes when uploading csv

Asked

Viewed 211 times

0

I did the following instruction to upload a csv to the database:

public void importarBaseBruta(File arquivo) {
    try {
        this.limparBaseBruta();
        this.con.conectar();
        this.stm = this.con.getStm();
        System.out.println("- IMPORTANDO BASE BRUTA");
        String path = arquivo.getPath().replace("\\", "/");
        String query = "LOAD DATA LOCAL INFILE '" + path + "' INTO TABLE base_bruta \n"
                + "CHARACTER SET 'latin1' \n" + "FIELDS TERMINATED BY ';' ENCLOSED BY '\"' \n" + " IGNORE 2 LINES;";
        this.stm.executeUpdate(query);
        this.con.fechar();
        System.out.println("- TERMINOU DE IMPORTAR A BASE BRUTA DIARIA");
    } catch (Exception e) {
        System.out.println("ERRO NO MOMENTO DE IMPORTAR: " + e.getMessage());
        e.printStackTrace();
    }
}

But when csv goes up to the bank the column moves because of quotation marks that are not removed:

inserir a descrição da imagem aqui

Displaced column:

inserir a descrição da imagem aqui

I would like to know how to remove it.

  • Reading each line of the file and doing a replace?

  • I made this method for that but it continues the same thing https://pastebin.com/2dMDPWcu

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.