My explanation might not be clear, sorry about that!
I am using NetBeans IDE 8.0 to create Java projects. I'm a beginner to Java programming and only started last Wednesday for work experience. Also for my CSV I'm using the following library: CSVReader
My mentor told me to create a program which outputs data as CSV so I can go to the CSV file and make a graph of the data. What it does is obtain the data size(Long) and create time(XML Gregorian Calendar) of the files in an online database using JPQL. If you want to have a read here is the schema: [SCHEMA](http://icatproject.org/mvn/site/icat/server/4.3.2/icat.core/schema.html#Datafile"ICAT schema").
Seems like the program is able to find the datafiles(I checked using debugger: 8 files on a 2 day range), but it does not seem to output the data as CSV, even though it creates the CSV files. In my code there will be a part for data count, I haven't done that yet. Also the user can input the date range in which they want the data from, although for testing purpose, I have made that part a comment so that I have a small range. Could you please check my code(I have edited out any unnecessary info. like the login part):
String outputFileCount = "C:\\Users\\me\\Documents\\CSV\\dataByCount.csv";
String outputFileSize = "C:\\Users\\me\\Documents\\CSV\\dataBySize.csv";
boolean alreadyExistsCount = new File(outputFileCount).exists();
boolean alreadyExistsSize = new File(outputFileSize).exists();
String FileSize;
Long DatafileCount;
Calendar calendar;
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
String Date;
List<Object> dfSearch = null;
CsvWriter csvOutputCount = new CsvWriter(new FileWriter(outputFileCount, true), ',');
CsvWriter csvOutputSize = new CsvWriter(new FileWriter(outputFileSize, true), ',');
if (typeOutput.equals("count")) {
if (!alreadyExistsCount) {
csvOutputCount.write("DataFile Create Time");
csvOutputCount.write("Datafile Count");
csvOutputCount.endRecord();
}
} else if (typeOutput.equals("size")){
if (!alreadyExistsSize) {
csvOutputSize.write("DataFile Create Time");
csvOutputSize.write("DataFile Size");
csvOutputSize.endRecord();
}
inputDates = "SELECT d FROM Datafile d WHERE d.datafileCreateTime BETWEEN {ts 2013-12-01 00:00:00} AND {ts 2013-12-02 23:59:59}";
dfSearch = icat.search(sessionId, inputDates);
for (Object datafile : dfSearch) {
Datafile dFile = (Datafile) datafile;
calendar = dFile.getDatafileCreateTime().toGregorianCalendar();
formatter.setTimeZone(calendar.getTimeZone());
Date = formatter.format(calendar.getTime());
csvOutputSize.write(Date); //Convert XMLGregorianCalendar to String
FileSize = Long.toString(dFile.getFileSize());
csvOutputSize.write(FileSize); //Convert long to String
csvOutputSize.endRecord();
}
}
}
}