Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ApplicationModuleRef amRef = null;
- ApplicationModuleImpl am = null;
- DBTransaction trs = null;
- CallableStatement stm = null;
- OutputStream sout = null;
- String IntNumber = "";
- String CurrId = "";
- IntNumber = session.getAttribute("NS0293FIntNumber").toString();
- CurrId = session.getAttribute("NS0293FcurId").toString();
- try {
- amRef = (ApplicationModuleRef) pageContext.findAttribute("NS0285_AM");
- am = (ApplicationModuleImpl) amRef.useApplicationModule();
- trs = (DBTransaction)am.getTransaction();
- OracleConnection conn = (OracleConnection)trs.createStatement(1).getConnection();
- int read = 100;
- byte b[] = new byte[read];
- stm = conn.prepareCall("{call AB.get_xls(?,?,?)}");
- BLOB newBlob = BLOB.createTemporary(conn, true, BLOB.DURATION_SESSION);
- OutputStream dbout = newBlob.getBinaryOutputStream();
- String retStr = "1";
- do {
- stm.setString(1, CurrId);
- stm.registerOutParameter(2, Types.VARCHAR);
- stm.registerOutParameter(3, Types.BLOB);
- stm.execute();
- retStr = stm.getString(2);
- } while (retStr.equals("1"));
- java.sql.Blob retBlob = stm.getBlob(3);
- long sizeout = retBlob.length();
- out.clearBuffer();
- response.setContentType("application/vnd.ms-excel");
- response.setHeader("Content-Disposition","attachment;filename="+IntNumber+".xls");
- response.setContentLength((int) sizeout);
- sout = response.getOutputStream();
- for (long i = 0; i*read < sizeout ; i++) {
- b = retBlob.getBytes(i*read + 1, read);
- sout.write(b, 0, b.length);
- }
- sout.flush();
- trs.commit();
- } catch (IOException io) {
- io.printStackTrace();
- response.setContentLength(-1);
- trs.rollback();
- } catch(SQLException e) {
- e.printStackTrace();
- response.setContentLength(-1);
- trs.rollback();
- } finally {
- try {
- stm.close();
- } catch (SQLException exc) {
- } finally {
- stm = null;
- }
- sout.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement