0

In my JSP page i had created a button(Download Result) and when i click the button it will display the save as dialog box. User will select a path to store the downloaded file. When the user click the download result button im getting all the records from a table and store it in the excel file. For this im trying to use COPY command which is in postgre.

My code :

<%@page import="java.sql.ResultSetMetaData"%>
<%@page import="java.util.ArrayList"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFCell"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
<%@ page import="java.io.PrintWriter" %>  
<%@ page contentType="application/excel" language="java" %>  



 <% 
   String fileName = "Result.xls";  
   String strHeader = "attachment;filename=" + fileName; 
   response.setContentType("application/vnd.ms-excel");

   PrintWriter op = response.getWriter();  
   PostgresConnection dbCon =  PostgresConnection.getInstance();
   Connection con = dbCon.getConnection();
   Statement st =con.createStatement();
   response.setHeader("Content-disposition",strHeader);


   st.execute("copy datas.del16 to D:/file.xls DELIMITER ',' CSV HEADER;");        


  %>

In "copy datas.del16 to D:/file.xls DELIMITER ',' CSV HEADER ", " D:/file.xls" has to be replaced with the path selected by the user.

Thanks, Karthika

Chris Travers
  • 25,424
  • 6
  • 65
  • 182

0 Answers0