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; } }