Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

problems during creation of excel report  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%@ page contentType = "application/vnd.ms-excel" pageEncoding="UTF-8"%>
<% response.setContentType("application/vnd.ms-excel"); %>
<%@ page language="java"%>
<%@ page import="java.sql.*,util.datasource.DAOUtils,javax.sql.DataSource,java.util.*" %>
<%@ page import="net.sf.jasperreports.engine.JasperExportManager" %>
<%@ page import="net.sf.jasperreports.engine.JasperManager" %>
<%@ page import="net.sf.jasperreports.engine.JasperCompileManager" %>
<%@ page import="net.sf.jasperreports.engine.JasperRunManager" %>
<%@ page import="net.sf.jasperreports.engine.JasperPrint" %>
<%@ page import="net.sf.jasperreports.engine.JasperReport" %>
<%@ page import="net.sf.jasperreports.engine.JRResultSetDataSource" %>
<%@ page import="net.sf.jasperreports.engine.export.JRPdfExporter"%>
<%@ page import="net.sf.jasperreports.engine.xml.JRXmlLoader" %>
<%@ page import="net.sf.jasperreports.engine.xml.JRXmlDigesterFactory" %>
<%@ page import="net.sf.jasperreports.view.JasperViewer" %>
<%@ page import="net.sf.jasperreports.engine.util.*"%>
<%@ page import="net.sf.jasperreports.engine.*"%>
<%@ page import="net.sf.jasperreports.engine.design.JasperDesign" %>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.text.*" %>
<%@ page import="java.io.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="net.sf.jasperreports.engine.util.JRLoader.*"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFCell"%>
<%

Connection con = null;

try
{
con = DAOUtils.getDBConnectionPost();
System.out.println("---concon---"+con);
String filename="C:/Documents and Settings/Administrator/Desktop/Qualification.xls" ;
HSSFWorkbook hwb=new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet("new sheet");
HSSFRow rowhead=sheet.createRow((short)0);
rowhead.createCell((short)0).setCellValue("Qualification Id");
rowhead.createCell((short)1).setCellValue("Qualification Name");
rowhead.createCell((short)2).setCellValue("Qualification Short Name");
//Class.forName("org.postgresql.Driver");
//Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/aptourism06032013","postgres","postgres");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery(" select * from HRMS_QUALIFICATION_MST ");
int i=1;
while(rs.next())
{
HSSFRow row=sheet.createRow((short)i);
row.createCell((short)0).setCellValue(rs.getString("qualification_id"));
row.createCell((short)1).setCellValue(rs.getString("qualification_name"));
row.createCell((short)2).setCellValue(rs.getString("qualification_short_name"));
i++;
}
FileOutputStream fileOut = new FileOutputStream(filename);
hwb.write(fileOut);
fileOut.close();
System.out.println("Your excel file has been generated!");
byte[] bytes = hwb.getBytes();


ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
//ouputStream.write(fileOut);
//ouputStream.flush();
//ouputStream.close();
try{
Runtime.getRuntime().exec("cmd /c start C:\\Documents and Settings\\Administrator\\Desktop\\Qualification.xls");
}catch(IOException e){
e.printStackTrace();
}
con.commit();
}
catch(Exception e)
{
if(con!=null)
{
con.rollback();
}
out.println("Exception-->"+e);
}
finally
{
DAOUtils.closeConnection(con);
//DAOUtils.closeStatement(st);
//DAOUtils.closeConnection(rs);
}
%>
 
author & internet detective
Sheriff
Posts: 38564
654
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch! I see a block of code, but not what the problem is. What error do you get? See TellTheDetails for more information about what is useful to provide.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!