try {
res.setContentType("application/pdf");
ServletOutputStream out = res.getOutputStream();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(
"SELECT PDF FROM PDF WHERE PDFID = " + req.getParameter("PDFID"));
if (rs.next()) {
BufferedInputStream pdfData =
new BufferedInputStream(rs.getBinaryStream("PDF"));
byte[] buf = new byte[4 * 1024]; // 4K buffer
int len;
while ((len = pdfData.read(buf, 0, buf.length)) != -1) {
out.write(buf, 0, len);
}
}
else {
res.sendError(res.SC_NOT_FOUND);
}
}
catch(SQLException e) {
// Report it
}