Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: want to resolve issue about discarding zeros of numeric values in csv

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question want to resolve issue about discarding zeros of numeric values in csv

    Hello Guys,

    I need your help on my query where I am exporting data into .csv file using java code after getting from DB.
    But I am seeing all the actual numeric values where initially zeros are coming has been discarded while being exported into csv file.


    @Amit


  2. #2
    Administrator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    24,848
    Thanks
    64
    Thanked 2,645 Times in 2,615 Posts

    Default Re: want to resolve issue about discarding zeros of numeric values in csv

    Can you post some code that shows the problem?

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Re: want to resolve issue about discarding zeros of numeric values in csv

    Quote Originally Posted by Norm View Post
    Can you post some code that shows the problem?
    Yes why not..?
    Quote Originally Posted by JAVA

    public class CsvWriter {
    private static CommonLogger logger = CommonLogger.getLogger();

    /**
    * This method is used to write data to an csv file.
    * @param fileName - Name of the csv file.
    */

    private void writeCSVFile(String filenane) {
    FileWriter writer=null;
    try {
    writer = new FileWriter(filenane);
    writer.write(CsvConstants.APPLICATION_NO);
    writer.write(',');
    writer.write(CsvConstants.POLICY_NO);
    writer.write(',');
    writer.write(CsvConstants.CSRID);
    writer.write(',');
    writer.write(CsvConstants.WORKTYPE);
    writer.write(',');
    writer.write(CsvConstants.WORKSTEP_NAME);
    writer.write(',');
    writer.write(CsvConstants.STATUS);
    writer.write(',');
    writer.write(CsvConstants.CASESTATUS);
    writer.write(',');
    writer.write('\n');
    addDataRows(writer);

    } catch (IOException e) {
    logger.logError("Exception in writeCSVFile(),while generating CSV file==", e);
    }
    finally{
    try {
    writer.close();
    } catch (IOException e) {
    logger.logError("Exception while closing writer object==",e);
    }
    }
    }

    private void addDataRows(FileWriter writer){
    //code to add rows into CSV file..
    WFStatusDAO wfstatusdao=WFStatusDAO.self();
    List<WFStatusDataVO> datalist=wfstatusdao.fetchWFStatusData();
    int counter=0;
    if(null!=datalist && datalist.size()>0){
    for(WFStatusDataVO statusDataVO : datalist) {
    try{
    if (null!=statusDataVO.getApplicationno() ) {
    writer.write(statusDataVO.getApplicationno());
    writer.write(',');
    }else{
    writer.write("");
    writer.write(',');
    }
    if (null!=statusDataVO.getPolicyno() ) {
    writer.write(statusDataVO.getPolicyno());
    writer.write(',');
    }else{
    writer.write("");
    writer.write(',');
    }
    writer.write(statusDataVO.getCsrid());
    writer.write(',');
    writer.write(statusDataVO.getWorktype());
    writer.write(',');
    writer.write(statusDataVO.getWorkstepname());
    writer.write(',');
    writer.write(statusDataVO.getStatus());
    writer.write(',');
    writer.write(statusDataVO.getCasestatus());
    writer.write('\n');
    counter++;
    }
    catch (IOException e) {
    logger.logError("Exception in addDataRows(),while writing data into CSV==", e);
    }
    }
    logger.logInfo("Total no of rows are returned="+counter);
    }else{
    logger.logInfo("NO data are available for provided SQL");
    }
    logger.logInfo("Out from CsvWriter.addDataRows()");
    }

    public static void main(String[] args) {
    System.out.println("CsvWriter.main().Execution started...");
    logger.logInfo("====CsvWriter.main().Report generation started====");
    long starttime=System.currentTimeMillis();
    //getting today's date to put into file name..
    Calendar cal=Calendar.getInstance();
    String todayDate=new SimpleDateFormat("dd-MMM-yyyy").format(cal.getTime());
    System.out.println("Report for todayDate=="+new SimpleDateFormat("dd-MMM-yyyy HH:MM").format(cal.getTime()));
    logger.logInfo("Report for Date=="+new SimpleDateFormat("dd-MMM-yyyy HH:MM").format(cal.getTime()));
    String filename=CsvPropertyReader.getProperty(CsvConstant s.CSVFILEPATH)+CsvPropertyReader.getProperty(CsvCo nstants.DEFAULTFILENAME)+CsvConstants.SEPARATOR+to dayDate+CsvPropertyReader.getProperty(CsvConstants .FILEEXTENTION) ;
    logger.debug("CsvWriter.main().filename="+filename );
    new CsvWriter().writeCSVFile(filename);
    long endtime = System.currentTimeMillis();
    logger.debug("====CsvWriter.main().Total time taken to generate CSV is="+(endtime-starttime)+" milliseconds ====");
    }
    }


Similar Threads

  1. issue with return values stuck at 0
    By dendoc01 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 4th, 2013, 06:00 PM
  2. How do I get numeric values from JTextField??
    By zlloyd1 in forum AWT / Java Swing
    Replies: 2
    Last Post: January 22nd, 2013, 04:31 PM
  3. Cannot Resolve Symbol Error
    By tyeeeee1 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: December 6th, 2012, 05:12 PM
  4. Replies: 4
    Last Post: November 28th, 2012, 03:01 PM
  5. Hexadecimal to Binary WITH leading zeros???
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 6th, 2012, 09:27 PM

Tags for this Thread