skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Saturday, October 13, 2012

Export to CSV from JSP Page

Posted by Raju Gupta at 5:00 PM – 0 comments
 
The code snippet helps to export data from a jsp page which has fetched data from SQL Database into CSV format.

private static  void writeCsv(FileWriter writer , String [] array ) throws Exception{
  try{
   int sizeOfArr = array.length;
   int index = 0; 
   while(index < sizeOfArr){
    writer.append(array[index] == null ? "" : array[index]);
    if( index != (sizeOfArr-1)){
     writer.append(",");
    }else{
     writer.append('\n');
    }
    index++;
   }
  }catch(Exception e){
    e.printStackTrace();
    throw e;
  }
 }


Labels: CSV Example , JSP Example

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger