Search This Blog

Wednesday, August 28, 2019

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.
BlobClob
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:
  • TINYBLOB
  • BLOB
  • MEDIUMBLOB
  • LONGBLOB
MySQL supports this with the following datatypes:
  • TINYTEXT
  • TEXT
  • MEDIUMTEXT
  • LONGTEXT
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:
  • setBlob()
  • setBinaryStream()
To store Clob JDBC (PreparedStatement) provides methods like:
  • setClob()
  • setCharacterStream()
And to retrieve (ResultSet) Blob it provides methods like:
  • getBlob()
  • getBinaryStream
And to retrieve (ResultSet) Clob it provides methods like:
  • getClob()
  • getCharacterStream()

No comments: