Java-MySQL-选择查询输出文件-文件保存在哪里 [英] java - mysql - select query outfile - where is file getting saved
问题描述
使用jdbc从Java连接到mysql数据库. 声明查询
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'";
使用executQuery(query)执行查询.
executing query using executQuery(query).
如何更改以上代码以将DataFormatted.csv保存到C驱动器根目录
how to change above code to save DataFormatted.csv into c drive root directory
推荐答案
文件保存在哪里.
在MySQL服务器的当前工作目录中.它是哪一个取决于MySQL服务器的执行和配置方式.最好的方法是将CSV文件的位置更改为固定位置.
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.
如何更改以上代码以将DataFormatted.csv保存到C驱动器根目录
只需将'DataFormatted.csv'
更改为'C:/DataFormatted.csv'
.
请注意,如果您也想通过Java访问CSV文件,则Java代码和MySQL服务器都应在相同计算机上运行.如果它们在物理上不同的计算机上运行,那么您可能会寻找其他方法来访问CSV文件,例如通过FTP生成的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.
这篇关于Java-MySQL-选择查询输出文件-文件保存在哪里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!