CLOBs
For the most part, a CLOB behaves just like a BLOB, except it
exists specifically for storing character data and is subject to
National Language Support
(NLS) character conversion. Whereas an
oracle.sql.BLOB
object has methods for handling
binary data, an
oracle.sql.CLOB
object has methods for reading and
writing both ASCII and Unicode (character) data. If you use the
ASCII
methods -- getAsciiStream( )
, setAsciiStream( )
, and getAsciiOutputStream( )
-- the driver translates the client character set of
ASCII to and from the database’s character set. If you use the
character methods -- getCharacterStream( )
, setCharacterStream( )
, getCharacterOutputStream( )
, and putChars( )
-- the driver translates the client
character set of Unicode to the database’s character set. The
database will handle the data as ASCII if the database character set
is ASCII; otherwise, the database will perform NLS character set
translations to maintain the Unicode characters if the database uses,
for example, the UTF-8 character set.
You can just as easily store text in a BLOB, so why should you use a CLOB instead of a BLOB? The most compelling reason to use a CLOB is its NLS abilities, that is, its abilities to handle NLS character set conversions. And to access these, you need a database that uses a UTF-8 character set, and you need to use the character methods. The only advantage to using the ASCII methods is that they are more efficient. However, if you code your applications with the character ...
Get Java Programming with Oracle JDBC now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.