0

I am tring to write more than one databaase table into a single csv file.

how can i do that.

this is my current code for writing into my CSV using OPEN 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) {}
}
Jacob
  • 14,463
  • 65
  • 207
  • 320
Aman
  • 85
  • 9

1 Answers1

0

I'm having a Déjà vu.

You should improve you inter-class/course/seminar/whatever-communication. See HERE

Or at least try a search.

Community
  • 1
  • 1
Dawnkeeper
  • 2,844
  • 1
  • 25
  • 41
  • I did as a matter of fact... please read the problem statement more carefully prior to commenting. I am trying to write more than 1 "Tables" into one csv file not Strings. – Aman Jun 06 '14 at 06:25
  • That is still possible in that way. For each table{Foreach row {create string array and pass to `writeNext`}}. The only problem is, that you can't write header information in a meaningful way if the tables have a different structure. If they have the same structure you could union them to get a uniform output. – Dawnkeeper Jun 06 '14 at 06:53