What is the difference between BLOB and CLOB datatypes?
Blob and Clob together are known as LOB(Large Object Type).
I have been pretty much fascinated by these two data types. According to Oracle Docs, they are presented as follows :
BLOB : Variable-length binary large object string that can be up to 2GB (2,147,483,647) long. Primarily intended to hold non-traditional data, such as voice or mixed media. BLOB strings are not associated with a character set, as with FOR BIT DATA strings.
CLOB : Variable-length character large object string that can be up to 2GB (2,147,483,647) long. A CLOB can store single-byte character strings or multibyte, character-based data. A CLOB is considered a character string.
Following are the major differences between Blob and Clob data types.
Blob | Clob |
---|---|
The full form of Blob is Binary Large Object. | The full form of Clob is Character Large Object. |
This is used to store large binary data. | This is used to store large textual data. |
This stores values in the form of binary streams. | This stores values in the form of character streams. |
Using this you can store files like text files, PDF documents, word documents etc. | Using this you can stores files like videos, images, gifs, and audio files. |
MySQL supports this with the following datatypes:
| MySQL supports this with the following datatypes:
|
In JDBC API it is represented by java.sql.Blob Interface. | In JDBC it is represented by java.sql.Clob Interface. |
The Blob object in JDBC points to the location of BLOB instead of holding its binary data. | The Blob object in JDBC points to the location of BLOB instead of holding its character data. |
To store Blob JDBC (PreparedStatement) provides methods like:
| To store Clob JDBC (PreparedStatement) provides methods like:
|
And to retrieve (ResultSet) Blob it provides methods like:
| And to retrieve (ResultSet) Clob it provides methods like:
|
Published on Java Code Geeks with permission by Ahmad Gohar, partner at our JCG program. See the original article here: What is the difference between BLOB and CLOB datatypes? Opinions expressed by Java Code Geeks contributors are their own. |
Shouldn’t the file types that can be stored be the other way round?
Blob – videos, images, gifs, and audio files
Clob – text files, PDF documents, word documents etc