I have created export to excel data code using
java poi. This code gets executed very finely on my local
tomcat server, but i upload my project on the linux server, and there the code is not getting executed.
Below is my export to java function, anybody please tell me if i am going wrong in this code.
in this code i m first creating an exel file and saving in 'temp' folder i.e. the xls file get stored at this C:\Documents and Settings\Admin\.netbeans\7.1\apache-tomcat-7.0.22.0_base\temp\temp4750857184897442788.xls
public class ExportData {
Connection conn = null;
ResultSet rs1 = null;
PreparedStatement ps1 = null;
Workbook wb = new HSSFWorkbook();
HSSFSheet sheet = (HSSFSheet) wb.createSheet("new sheet");
HSSFRow rowhead = sheet.createRow((short) 2);
int index = 3;
int sno = 0;
public void exportCre(
String sql) {
try {
conn = DbConnection.getConnection();
ps1 = conn.prepareStatement(sql);
rs1 = ps1.executeQuery();
rowhead.createCell((short) 0).setCellValue("SNo");
rowhead.createCell((short) 1).setCellValue("Date");
rowhead.createCell((short) 2).setCellValue("Login Name");
System.out.println("Sql completed");
while (rs1.next()) {
sno++;
HSSFRow row = sheet.createRow((short) index);
row.createCell((short) 0).setCellValue(sno);
row.createCell((short) 1).setCellValue(rs1.getString(1));
row.createCell((short) 2).setCellValue(rs1.getString(2));
index++;
}
File tempXlsx = File.createTempFile("temp", ".xls");
wb.write(new FileOutputStream(tempXlsx));
Desktop.getDesktop().open(tempXlsx);
} catch (Exception e) {
e.printStackTrace();
}
}
}