5337df4141fb54c0a1a6ba2145519adbb20977e2.svn-base 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package UIB.UIB03.ZBS;
  2. import java.io.OutputStream;
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import CoreFS.SA01.CoreIComponent;
  7. import UIB.COM.XmlSqlParsersFactory;
  8. import oracle.sql.BLOB;
  9. /**
  10. *
  11. * @desc
  12. * @author meiguiping
  13. * @date 2010 11:24:56 PM
  14. */
  15. public class BlobOutputStream extends CoreIComponent
  16. {
  17. public BlobOutputStream(){}
  18. public BLOB getBLob(String sql ,String blobName , String param) throws Exception
  19. {
  20. Connection con = null;
  21. PreparedStatement pstm = null;
  22. BLOB blob = null;
  23. try
  24. {
  25. con = this.getDao("KgDao").getConnection();
  26. pstm = con.prepareStatement(XmlSqlParsersFactory.getSql(sql));
  27. pstm.setString(1, param);
  28. ResultSet rs = pstm.executeQuery();
  29. if(rs.next())
  30. {
  31. blob = (oracle.sql.BLOB)rs.getBlob(blobName);
  32. // blob.close();
  33. }
  34. }catch(Exception ex)
  35. {
  36. throw new Exception("获取BLOB对象异常!");
  37. }
  38. finally
  39. {
  40. try
  41. {
  42. // if(pstm !=null)
  43. // pstm.close();
  44. if(con != null)
  45. con.close();
  46. }catch(Exception e)
  47. {
  48. throw new Exception("数据库连接异常!");
  49. }
  50. }
  51. return blob;
  52. }
  53. public OutputStream getOutputStream(String sql ,String blobName, String param)throws Exception
  54. {
  55. OutputStream os = getBLob(sql ,blobName, param).getBinaryOutputStream();
  56. // os.close();
  57. return os;
  58. }
  59. }