Home » Software Development » What is the difference between BLOB and CLOB datatypes?

About Ahmad Gohar

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.

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.

(0 rating, 0 votes)
You need to be a registered member to rate this.
1 Comment Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Taavi K. Recent comment authors

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

  Subscribe  
newest oldest most voted
Notify of
Taavi K.
Guest
Taavi K.

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