Java CLOB type to String type

Source: Internet
Author: User

In the first two days of the project, there is a field of type CLOB, which cannot be directly converted to a string type when fetching data with pure SQL. So you have to manually turn, and then use the following code, posted here to share, if the small partners need to directly take to use, this pro-test is can be used oh ...

Not much to say, the code is the kingly ...

Clob type to string public    string clobtostring (Clob Clob) throws SQLException, IOException {      String restring = ""; 
   reader is = Clob.getcharacterstream ();//Get stream      bufferedreader br = new BufferedReader (is);      String s = br.readline ();      StringBuffer sb = new StringBuffer ();      while (s! = null) {///execution loop takes all strings out of the value to StringBuffer from StringBuffer to string      sb.append (s);      s = Br.readline ();      }      restring = Sb.tostring ();      if (br!=null) {          br.close ();      }      if (is!=null) {          is.close ();      }      return restring;     }


is not very simple wow, small friends to try it ...

Java CLOB type to String type

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.