title: How to export JDBC template result to excel sheet
body: <p>PersonDAO.java:</p>
  
  <pre><code>public List&lt;Map&lt;String, Object&gt;&gt; searchPersons(Person person)  
      String sql = "SELECT * FROM PERSON";
      List&lt;Map&lt;String, Object&gt;&gt; result = jdbcTemplate.queryForList(sql);
      return result;
  }
  </code></pre>
  
  <p>How to convert the data in the <code>result</code> to download as excel sheet.</p>
  
  <p>Tried with Apache POI:</p>
  
  <pre><code>Workbook workbook = new HSSFWorkbook();
  Sheet sheet = workbook.createSheet("Person Detail");
  
  Object[][] persons = {
      {"PersonNAmeA", 1001},
      {"PersonNAmeB", 1002},
      {"PersonNAmeC", 1003}, 
  };
  
  int rowCount = 0;
  
  for (Object[] person : persona) {
  Row row = sheet.createRow(++rowCount);
  
  int columnCount = 0;
  
  for (Object field : person) {
      Cell cell = row.createCell(++columnCount);
      if (field instanceof String) {
          cell.setCellValue((String) field);
      } else if (field instanceof Integer) {
          cell.setCellValue((Integer) field);
      }
  }
  
  }
  
  
  try (FileOutputStream outputStream = new FileOutputStream("PersonDetail.xlsx")) {
  workbook.write(outputStream);
  } catch (FileNotFoundException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  }
  </code></pre>
  
  <p>No error, but PersonDetail.xlsx has not been created. What could be wrong in the code.</p>
  
  <p>Can anyone help on this issue.
  Thanks</p>