• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error in downloading ZipoutputStream

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Trying to download zipOutPutStream created with data from database in JSP , I am getting a error "Client terminated connection to server before the entire response was sent. Status code: -1". Any one have idea on this problem.
Given below is the snipnet of the code.
<%@ page contentType="text/zip"%>
<%@ page import="com.zip.fr.*,java.sql.*,javax.sql.*,javax.naming.*,java.io.*,java.util.zip.*" session="true"%>
<%
//************** Get Connection to DB2
DataSource ds = null;
Connection con = null;
try
{
Context ctx = new InitialContext();
ds = (DataSource) ctx.lookup("jdbc/xxx");
con = ds.getConnection("yyyyy", "zzzzz");
System.out.println("using my connection");
}
catch (SQLException errSQL)
{
//hhhhhh
}
catch(Exception errException)
{
//yyyy
}

try
{
String headerName = "header.txt";
String fileName = "test.txt";
//************** Get Current Date
java.util.Calendar c = java.util.Calendar.getInstance();
String ccyy = "" + c.get(java.util.Calendar.YEAR);
String mm = "" + (c.get(java.util.Calendar.MONTH) + 1);
if (mm.length() == 1)
{
mm = "0" + mm;
}
String dd = "" + c.get(java.util.Calendar.DAY_OF_MONTH);
if (dd.length() == 1)
{
dd = "0" + dd;
}
//************** Establish Output Stream
OutputStream os = response.getOutputStream();
ZipOutputStream zos = new ZipOutputStream(os);
//************** Create Header Entry into Zip File
ZipEntry zipEntry1 = new ZipEntry(headerName);
zos.putNextEntry(zipEntry1);

zos.write(("Download Date of the file was : " + mm + "/" + dd + "/" + ccyy).getBytes());
zos.closeEntry();
zos.flush();

zos.putNextEntry(new ZipEntry("test.txt"));
//************** Process SE High Risk File

String sql = "CALL zzzz (?)";
CallableStatement callStmt = con.prepareCall(sql);
callStmt.setString(1," ");
callStmt.execute();

ResultSet rs = callStmt.getResultSet();
int i = 0;

while (rs.next())
{
zos.write((rs.getString(1) + " " + rs.getString(2) + " " + rs.getString(3) + " " + rs.getString(4) + " " + rs.getString(5) + " " + rs.getString(6) + " " + rs.getString(7) + " " + rs.getString(8) + "\r" + "\n").getBytes());
zos.flush();
i++;

}

zos.closeEntry();
zos.flush();
rs.close();
callStmt.close();
con.close();

zos.close();
os.close();
}
catch(Exception errException)
{
//
}
%>
Regards,
Cheers prasad
 
reply
    Bookmark Topic Watch Topic
  • New Topic