我正在尝试将多个数据库表写入单个csv文件中。
我该怎么做。
这是我目前使用OPEN csv写入我的CSV的代码。
try {
ResultSet query_set1 = stmt2.executeQuery("SELECT * FROM ARTIFACT_VERSION T1 INNER JOIN ( SELECT ARTIFACTNAME , MAX(DEPLOYMENT_TIME) AS DEPLOYMENT_TIME FROM ARTIFACT_VERSION GROUP by ARTIFACTNAME) T2 ON T1.ARTIFACTNAME = T2.ARTIFACTNAME AND T1.DEPLOYMENT_TIME = T2.DEPLOYMENT_TIME"); //fetch all the rows from the department table
try {
FileWriter my_csv=new FileWriter(filePath+"/artifact_"+username+".csv");
CSVWriter my_csv_output=new CSVWriter(my_csv); //Create a writer object
boolean includecolumnnames=true;
my_csv_output.writeAll(query_set1,includecolumnnames); //write output by directly reading the Resultset, include column names in report
my_csv_output.close();
System.out.println("created");
}
finally {
try { query_set1.close(); } catch (Exception ignore) {}
}
}
finally {
try { stmt2.close(); } catch (Exception ignore) {}
}
}
finally {
try { connection1.close(); } catch (Exception ignore) {}
}