connecting to a mysql database from java using jdbc. declaring a query
String query =
"SELECT *"+
"FROM tt2"+
"INTO OUTFILE 'DataFormatted.csv'"+
"FIELDS TERMINATED BY ','"+
"ENCLOSED BY '\"'" +
"LINES TERMINATED BY '\n'";
executing query using executQuery(query).
how to change above code to save DataFormatted.csv into c drive root directory
where is file getting saved.
In the current working directory of the MySQL server. Which one it is depends on how the MySQL server is executed and configured. Best is to change the location of the CSV file to a fixed location.
how to change above code to save DataFormatted.csv into c drive root directory
Just change 'DataFormatted.csv'
by 'C:/DataFormatted.csv'
.
Be aware that both Java code and the MySQL server should run at physically the same machine if you want to access the CSV file by Java as well. If they runs at physically different machines, then you'll probably look for other ways to access the CSV file, e.g. FTP'ing the generated CSV file.