I am able to open the database file and get the query name and the statement. How do I output the query data to a csv? I thought he below exportWriter would do it but it doesn't work.
Database db = Database.open(new File(args[0]));
for(Query query : db.getQueries()) {
System.out.println(query.getName() + ": " + query.toSQLString());
if query.getName() = "thequerytooutput" {
BufferedWriter csvOut = new BufferedWriter(new OutputStreamWriter(System.out));
ExportUtil.exportWriter(db, query.getName(), csvOut, true, null, '"',
SimpleExportFilter.INSTANCE);
}
}
I think a better option would be to first store your values from the database into a "two dimensional" list of Strings( I'm assuming you know how to do that[if not, tell me and I'll clarify more]). And then use FileWriter to write the array into a CSV file.
This example was taken from stackabuse.com