title: generating report in excel sheet in java
body: <p>I want to generate Excel Report but I am not able to generate excel report , I don't know what is the problem ?</p>
  
  <p>I need to generate automated report everytime I click on generate report button. 
  I am using sqlyog,my table name is final and my database name is etc. my database table entries are not static so I need an automated report .</p>
  
  <p>I am using Eclipse IDE
  Is it that I need to use any more external api.</p>
  
  <pre><code>import java.io.File;
  import java.io.FileOutputStream;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.ResultSet;
  import java.sql.Statement;
  import org.apache.poi.hssf.usermodel.HSSFCell;
  import org.apache.poi.hssf.usermodel.HSSFRow;
  import org.apache.poi.hssf.usermodel.HSSFSheet;
  import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  
  public class ExcelDatabase {
  public static void main(String[] args) throws Exception {
      Class.forName("com.mysql.jdbc.Driver");
      Connection connect = DriverManager.getConnection("jdbc:mysql://localhost/etc", "root", "");
  
      Statement statement = connect.createStatement();
      ResultSet resultSet = statement.executeQuery("select * from final");
      HSSFWorkbook workbook = new HSSFWorkbook();
      HSSFSheet spreadsheet = workbook.createSheet("engine report");
      HSSFRow row = spreadsheet.createRow(1);
      HSSFCell cell;
      cell = row.createCell(1);
      cell.setCellValue("engine_code");
      cell = row.createCell(2);
      cell.setCellValue("var1");
      cell = row.createCell(3);
      cell.setCellValue("var2");
      cell = row.createCell(4);
      cell.setCellValue("var3");
      cell = row.createCell(5);
      cell.setCellValue("var4");
      cell = row.createCell(6);
      cell.setCellValue("var5");
      cell = row.createCell(7);
      cell.setCellValue("User_Name");
      cell = row.createCell(8);
      cell.setCellValue("time_stamp");
      int i = 2;
      while (resultSet.next()) {
          row = spreadsheet.createRow(i);
          cell = row.createCell(1);
          cell.setCellValue(resultSet.getInt("ec"));
          cell = row.createCell(2);
          cell.setCellValue(resultSet.getString("v1"));
          cell = row.createCell(3);
          cell.setCellValue(resultSet.getString("v2"));
          cell = row.createCell(4);
          cell.setCellValue(resultSet.getString("v3"));
          cell = row.createCell(5);
          cell.setCellValue(resultSet.getString("v4"));
          cell = row.createCell(6);
          cell.setCellValue(resultSet.getString("v5"));
          cell = row.createCell(7);
          cell.setCellValue(resultSet.getString("user"));
          cell = row.createCell(8);
          cell.setCellValue(resultSet.getString("time"));
          i++;
      }
      FileOutputStream out = new FileOutputStream(new File("exceldatabase.xls"));
      workbook.write(out);
      out.close();
      System.out.println("exceldatabase.xls written successfully");
   }
  }
  </code></pre>