I am trying to download the database data in csv format but it indicates that the SQL syntax is wrong.
public void exportarBaseRespostaPI() {
String banco = "b2wentregascorreios";
String tabela = "baserespmanifest";
String caminho = "C:\Users\wesley.costa\Desktop\wesley.costa\backup-correios\base_resposta_pi\base_resposta_pi.csv";
new File(caminho).delete();
try (Connection conn = connBD.Conectar(banco); Statement stmt = conn.createStatement()) {
try {
stmt.execute("SELECT 'codCorreio', 'codPI', 'respostaMsg', 'dataResp'\r\n" + " FROM " + tabela
+ "INTO OUTFILE '" + caminho + "' \n"
+ "FIELDS TERMINATED BY ';' ENCLOSED BY '\"' \n" + "LINES TERMINATED BY '\r\n';");
} catch (SQLException e) {
System.out.println(e.getMessage());
}
} catch (ClassNotFoundException | SQLException e) {
System.out.println(e.getMessage());
}
}
This is an exception:
(conn = 127002095) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OUTFILE 'C: \ Users \ wesley.costa \ Desktop \ wesley.costa \ backup-mails \ base_respost' at line 2 SELECT codCorreio, codPI, responseMsg, dataResp FROM baserespmanifest INTO OUTFILE 'C: \ Users \ wesley.costa \ Desktop \ wesley.costa \ backup-mails \ base_post_basics \ base_post_cs.csv' FIELDS TERMINATED BY ';' ENCLOSED BY '"' LINES TERMINATED BY '';