BLOBs and CLOBs
As users began to increase the volume of data stored in databases, vendors introduced support for large objects (LOBs). The two varieties of LOBs, binary large objects (BLOBs) and character large objects (CLOBs), store large amounts of binary or character data, respectively. The SQL99 specification formally defined these data types.
Support for LOB types across databases varies. Some don’t
support them at all, and most have unique type names (BINARY, LONG RAW, and so forth). JDBC 1.0 makes programs retrieve
BLOB and CLOB data using the getBinaryStream() or getAsciiStream() methods. (A third method,
getUnicodeStream(), has been
deprecated in favor of the getCharacterStream() method, which returns a
Reader.)
As of JDBC 2.0, the ResultSet
interface includes getBlob() and
getClob() methods, which return
Blob and Clob objects, respectively. The Blob and Clob objects themselves allow access to
their data via streams (the getBinaryStream() method of Blob and the getCharacterStream() method of Clob) or via direct-read methods (the getBytes() method of Blob and the getSubString() method of Clob).
To retrieve the data from a CLOB, simply retrieve the Clob object and call the getCharacterStream() method:
String s;
Clob clob = blobResultSet.getBlob("CLOBFIELD");
BufferedReader clobData = new BufferedReader(clob.getCharacterStream());
while((s = clobData.readLine()) != null)
System.out.println(s);In addition, you can set Blob
and Clob objects when you are working with a ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access