Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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
Posts: 39084
714
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.
 
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!