Java obtains the CLOB field in Oracle and converts it to String

Source: Internet
Author: User
Java obtains the CLOB field in Oracle and converts it to String: try {PreparedStatementstmtsession. connection (). prepareStatement (SQL); Result

Java obtains the CLOB field in Oracle and converts it to String: try {PreparedStatement stmt = session. connection (). prepareStatement (SQL); Result

Homepage → Database Technology

Background:

Read News

Java obtains the CLOB field in Oracle and converts it to String

[Date:] Source: Linux community Author: Linux [Font:]

Java obtains the CLOB field in Oracle and converts it to String:

Try {
PreparedStatement stmt = session. connection (). prepareStatement (SQL );
ResultSet rs = stmt.exe cuteQuery ();
While (rs. next ())
{
Clob clob = (Clob) rs. getObject (1 );
Result = ClobToString (clob );
}

} Catch (HibernateException e ){
E. printStackTrace ();
} Catch (SQLException e ){
E. printStackTrace ();
} Catch (IOException e ){
E. printStackTrace ();
} Finally {
Session. close ();
}

// Convert oracle. SQL. Clob type to String type

Public String ClobToString (Clob clob) throws SQLException, IOException {

String reString = "";
Reader is = clob. getCharacterStream (); // get the stream
BufferedReader br = new BufferedReader (is );
String s = br. readLine ();
StringBuffer sb = new StringBuffer ();
While (s! = Null) {// execute the loop to retrieve all strings and pay the value to StringBuffer, which is converted from StringBuffer to STRING.
Sb. append (s );
S = br. readLine ();
}
ReString = sb. toString ();
Return reString;
}

  • 0
  • Oracle date timestamp millisecond-time function Summary

    Install MySQL 7.2 in FreeBSD 4.0

    Oracle Basics

    Image Information

    View All comments in this article (0)

    Comments

    Latest Information

    Popular this week

    Introduction to Linux community-advertisement service-website map-help Info-contact us
    The articles published on this site (LinuxIDC) do not mean that they agree with the statement or description. They only provide more information and do not constitute any suggestions.


    Copyright©2006-2011 Linux community All rights reserved Zhejiang ICP backup No. 06018118

    ,

    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.