Advertisement
Guest User

Untitled

a guest
Jul 25th, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. ApplicationModuleRef amRef = null;
  2. ApplicationModuleImpl am = null;
  3. DBTransaction trs = null;
  4. CallableStatement stm = null;
  5. OutputStream sout = null;
  6. String IntNumber = "";
  7. String CurrId = "";
  8. IntNumber = session.getAttribute("NS0293FIntNumber").toString();
  9. CurrId = session.getAttribute("NS0293FcurId").toString();
  10. try {
  11. amRef = (ApplicationModuleRef) pageContext.findAttribute("NS0285_AM");
  12. am = (ApplicationModuleImpl) amRef.useApplicationModule();
  13. trs = (DBTransaction)am.getTransaction();
  14. OracleConnection conn = (OracleConnection)trs.createStatement(1).getConnection();
  15. int read = 100;
  16. byte b[] = new byte[read];
  17. stm = conn.prepareCall("{call AB.get_xls(?,?,?)}");
  18. BLOB newBlob = BLOB.createTemporary(conn, true, BLOB.DURATION_SESSION);
  19. OutputStream dbout = newBlob.getBinaryOutputStream();
  20. String retStr = "1";
  21. do {
  22. stm.setString(1, CurrId);
  23. stm.registerOutParameter(2, Types.VARCHAR);
  24. stm.registerOutParameter(3, Types.BLOB);
  25. stm.execute();
  26. retStr = stm.getString(2);
  27. } while (retStr.equals("1"));
  28. java.sql.Blob retBlob = stm.getBlob(3);
  29. long sizeout = retBlob.length();
  30. out.clearBuffer();
  31. response.setContentType("application/vnd.ms-excel");
  32. response.setHeader("Content-Disposition","attachment;filename="+IntNumber+".xls");
  33. response.setContentLength((int) sizeout);
  34. sout = response.getOutputStream();
  35. for (long i = 0; i*read < sizeout ; i++) {
  36. b = retBlob.getBytes(i*read + 1, read);
  37. sout.write(b, 0, b.length);
  38. }
  39. sout.flush();
  40. trs.commit();
  41. } catch (IOException io) {
  42. io.printStackTrace();
  43. response.setContentLength(-1);
  44. trs.rollback();
  45. } catch(SQLException e) {
  46. e.printStackTrace();
  47. response.setContentLength(-1);
  48. trs.rollback();
  49. } finally {
  50. try {
  51. stm.close();
  52. } catch (SQLException exc) {
  53. } finally {
  54. stm = null;
  55. }
  56. sout.close();
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement