Software Development

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()

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.

Ahmad Gohar

Technical Team Leader with 9+ years experience in designing and developing enterprise Solution using Oracle, IBM, and Open Source. With a solid technical and academic background. Strong technical project management experience, coordinate demo's for QA team, performing code, design and test plan reviews.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Taavi K.
Taavi K.
4 years ago

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

Back to top button