如何使用打开的CSV将多个数据库表写入一个.csv文件?

时间:2014-06-05 11:27:16

标签: java oracle parsing opencsv

我正在尝试将多个数据库表写入单个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) {}
}

1 个答案:

答案 0 :(得分:0)

我有一个Déjàvu。

你应该改善课间/课程/研讨会/任何沟通。见HERE

或至少尝试搜索。