Click here to Skip to main content
13,250,453 members (59,235 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I am getting some issue with SuperCSV parser. I have created a web application module to import CSV file to DB. After the import process the user will be displayed the summary like, the total number of records in input file, the total number of good records that got imported to db and the total number of rejected records. The user can download the success and error records to verify.

The issue is some duplicate records are added to success and error files. For example the user gets a message as follows:

Total number of records: 2099
Number of good records: 1694
Number of skipped records: 405
Click to download success file: Import_20121012184828_success.csv
Click to download error file: Import_20121012184828_errors.csv

When we check the db the number of records in the table is exactly '1694' (Same as number of good records as expected.). But in Import_20121012184828_success.csv file there are '1741' records. But in eclipse console it prints same as in db i.e after the last success record there is no duplication. So once exited from the loop and when I call successCsvMapWriter.close(); and errorCsvMapWriter.close(); some where from buffer the records are getting added up. I cant figure this out.

Note: For small number of inputs I din't notice any issues at all.

Following is the code to create the resultant files:

File successFile = new File(csvFileDetails.getSuccessFileUrl());
    File errorFile = new File(csvFileDetails.getErrorFileUrl());
    // Save Result files.
    String[] header = csvFileDetails.getHeader();
    String[] errorFileHeader = ArrayUtils.add(header,
    // Also tried CsvPreference.STANDARD_PREFERENCE 
    ICsvMapWriter successCsvMapWriter = new CsvMapWriter(new BufferedWriter(
        new FileWriter(successFile)), CsvPreference.EXCEL_PREFERENCE);
    ICsvMapWriter errorCsvMapWriter = new CsvMapWriter(new BufferedWriter(
        new FileWriter(errorFile)), CsvPreference.EXCEL_PREFERENCE);
    int errorCount = 0;
    int successCount = 0;
    for (Map<String, String> csvRecord : csvAsList) {
        if (csvRecord.get(CatalogImportConstanst.CSV_ERROR_HEADER) != null
            && csvRecord.get(CatalogImportConstanst.CSV_ERROR_HEADER).trim().length() > 0) {
            errorCsvMapWriter.write(csvRecord, errorFileHeader);
			System.out.println("Error record: "+ csvRecord);
        } else {
            successCsvMapWriter.write(csvRecord, header);
			System.out.println("Success record: "+ csvRecord);

Thanks in advance.
Posted 12-Oct-12 4:51am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The issue was in download section not with the parser, and I was busy with another task hence delayed to respond. Kindly forgive for my stupidity.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171114.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100