JAVA processes Clob large objects

Source: Internet
Author: User

BLOB stores data in binary format. For example, save a bitmap. CLOB uses CHAR to save data. For example, save the XML document.

 

1. Create a Clob object
The following code snippet illustrates how to create a Clob object, where rs is a ResultSet object:
Clob clob = rs. getClob (1 );
The variable clob can now be used to perform operations on the CLOB value, assuming that the CLOB value is saved in the first column of the result set rs.

Or

FileInputStream fis1 = new FileInputStream ("D:/test.txt ");
Pstmt. setBinaryStream (1, fis1, fis1.available ());
 

2. materialized Clob data
The same way as materialized Blob. However, the Clob interface provides three methods

Stored as a Java object in the customer's memory.
① Use getAsiiStream to convert the CLOB value into an Ascii byte response stream.
Clob notes = rs. getClob ("NOTES ");
Java. io. InputStream in = notes. getAsciiStream ();
Byte B = in. read ();

② Use getCharacterStream to convert the CLOB value into a Unicode character stream.
Clob notes = rs. getClob ("NOTES ");
Java. io. Reader reader = notes. getCharacterStream ();
Int c = reader. Read ();

③ Use getsubstring to convert all or part of the clob value into a string object.

Clob notes = Rs. getclob (4 );
String substring = notes. getsubstring (10, 5 );

Or

Long Len = notes. Length ();
String substring = notes. getsubstring (1, (INT) Len );

3. Storing and updating clob objects are similar to storing and updating blob objects. (For details, refer to the previous blog)

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.