Common classes for processing blob and clob

Source: Internet
Author: User
  1. Public class lobutil {
  2. Private Static final int buffer_size = 4096;
  3. Private lobutil (){
  4. }
  5. Public static synchronized void writeblob (resultset RS, string fieldname,
  6. Byte [] BUF) throws sqlexception, ioexception {
  7. If (BUF = NULL ){
  8. Return;
  9. }
  10. Outputstream OS = NULL;
  11. Blob B = Rs. getblob (fieldname );
  12. If (B = NULL ){
  13. Throw new sqlexception ("The Blob pointer just inserted or updated is null! ");
  14. } Else {
  15. // If (conn. isuseconnectionpool ()){
  16. // OS =
  17. // (Weblogic. JDBC. Vendor. Oracle. oraclethinblob) B). getbinaryoutputstream ();
  18. //}
  19. // Else {
  20. // OS = (Oracle. SQL. Blob) B). getbinaryoutputstream ();
  21. //}
  22. /**
  23. * @ Todo needs to be transformed into a universal database processing interface.
  24. */
  25. // <Modify author = "jdyao" time = "2005-07-26">
  26. Try {
  27. Method methodtoinvoke = B. getclass (). getmethod (
  28. "Getbinaryoutputstream", (class []) null );
  29. OS = (outputstream) methodtoinvoke. Invoke (B, (object []) null );
  30. } Catch (exception e ){
  31. Throw new sqlexception (E. getmessage ());
  32. }
  33. // OS = (Oracle. SQL. Blob) B). getbinaryoutputstream ();
  34. // </Modify>
  35. Bufferedoutputstream Bos = new bufferedoutputstream (OS );
  36. Bos. Write (BUF );
  37. Bos. Flush ();
  38. Bos. Close ();
  39. }
  40. }
  41. Public static synchronized void writeblob (resultset RS, string fieldname,
  42. Inputstream in) throws sqlexception, ioexception {
  43. If (in = NULL ){
  44. Return;
  45. }
  46. Outputstream OS = NULL;
  47. Blob B = Rs. getblob (fieldname );
  48. If (B = NULL ){
  49. Throw new sqlexception ("The Blob pointer just inserted or updated is null! ");
  50. } Else {
  51. // If (conn. isuseconnectionpool ()){
  52. // OS =
  53. // (Weblogic. JDBC. Vendor. Oracle. oraclethinblob) B). getbinaryoutputstream ();
  54. //}
  55. // Else {
  56. // OS = (Oracle. SQL. Blob) B). getbinaryoutputstream ();
  57. //}
  58. // <Modify author = "jdyao" time = "2005-07-26">
  59. Try {
  60. Method methodtoinvoke = B. getclass (). getmethod (
  61. "Getbinaryoutputstream", (class []) null );
  62. OS = (outputstream) methodtoinvoke. Invoke (B, (object []) null );
  63. } Catch (exception e ){
  64. Throw new sqlexception (E. getmessage ());
  65. }
  66. // OS = (Oracle. SQL. Blob) B). getbinaryoutputstream ();
  67. // </Modify>
  68. Bufferedoutputstream Bos = new bufferedoutputstream (OS );
  69. Bufferedinputstream Bis = new bufferedinputstream (in );
  70. Byte Buf [] = new byte [buffer_size];
  71. Int Len =-1;
  72. While (LEN = bis. Read (BUF ))! =-1 ){
  73. Bos. Write (BUF, 0, Len );
  74. }
  75. Bis. Close ();
  76. Bos. Flush ();
  77. Bos. Close ();
  78. }
  79. }
  80. Public static synchronized void writeclob (resultset RS, string fieldname,
  81. String BUF) throws sqlexception, ioexception {
  82. If (BUF = NULL ){
  83. Return;
  84. }
  85. Writer wR = NULL;
  86. Clob c = Rs. getclob (fieldname );
  87. If (C = NULL ){
  88. Throw new sqlexception ("The clob pointer just inserted or updated is null! ");
  89. } Else {
  90. // <Modify author = "jdyao" time = "2005-07-26">
  91. Try {
  92. Method methodtoinvoke = C. getclass (). getmethod (
  93. "Getcharacteroutputstream", (class []) null );
  94. WR = (writer) methodtoinvoke. Invoke (C, (object []) null );
  95. } Catch (exception e ){
  96. Throw new sqlexception (E. getmessage ());
  97. }
  98. // WR = (Oracle. SQL. clob) c). getcharacteroutputstream ();
  99. // </Modify>
  100. Bufferedwriter BW = new bufferedwriter (WR );
  101. Bw. Write (BUF );
  102. Bw. Flush ();
  103. Bw. Close ();
  104. }
  105. }
  106. Public static synchronized void writeclob (resultset RS, string fieldname,
  107. Inputstream in) throws sqlexception, ioexception {
  108. If (in = NULL ){
  109. Return;
  110. }
  111. Writer wR = NULL;
  112. Clob c = Rs. getclob (fieldname );
  113. If (C = NULL ){
  114. Throw new sqlexception ("The clob pointer just inserted or updated is null! ");
  115. } Else {
  116. // <Modify author = "jdyao" time = "2005-07-26">
  117. Try {
  118. Method methodtoinvoke = C. getclass (). getmethod (
  119. "Getcharacteroutputstream", (class []) null );
  120. WR = (writer) methodtoinvoke. Invoke (C, (object []) null );
  121. } Catch (exception e ){
  122. Throw new sqlexception (E. getmessage ());
  123. }
  124. // WR = (Oracle. SQL. clob) c). getcharacteroutputstream ();
  125. // </Modify>
  126. Bufferedwriter BW = new bufferedwriter (WR );
  127. Bufferedreader BR = new bufferedreader (New inputstreamreader (in ));
  128. Char Buf [] = new char [buffer_size];
  129. Int Len =-1;
  130. While (LEN = Br. Read (BUF ))! =-1 ){
  131. Bw. Write (BUF, 0, Len );
  132. }
  133. BR. Close ();
  134. Bw. Flush ();
  135. Bw. Close ();
  136. }
  137. }
  138. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.