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)