try{ connMgr = DBConnectionManager.getInstance(); con = connMgr.getConnection("sjo"); Debug.println("The connection is..."+con); stmt = con.createStatement(); String sql="select product,month,sales from testdata";
// Create a New XL Document HSSFWorkbook wb = new HSSFWorkbook(); // Make a worksheet in the XL document created HSSFSheet sheet = wb.createSheet();
// Create a row and put some cells in it. Rows are 0 based. HSSFRow row = sheet.createRow((short)0);
// Create a cell and put a value in it. HSSFCell cell = row.createCell((short)0);
cell.setCellValue("Product");
// Or do it on one line. row.createCell((short)1).setCellValue("Month"); row.createCell((short)2).setCellValue("Sales");
rs=stmt.executeQuery(sql);
int i=1; while(rs.next()){
System.out.println("i value in new row is........."+i);
HSSFRow nrow = sheet.createRow((short)i);
// Or do it on one line. nrow.createCell((short)0).setCellValue(rs.getString("Product")); nrow.createCell((short)1).setCellValue(rs.getString("Month")); nrow.createCell((short)2).setCellValue(new Integer(rs.getString("Sales")).intValue()); i++;
}
// The Output file is where the xls will be created FileOutputStream fOut = new FileOutputStream(outputFile); // Write the XL sheet wb.write(fOut); fOut.flush(); // Done Deal.. fOut.close();