Both BLOB and CLOB are large field types, BLOB is stored in binary, and CLOB can directly store text. In fact, the two are interchangeable, or you can directly replace the two with the LOB field. But for better management ORACLE database, Usually , information such as pictures, files, and music are stored in BLOB fields, and the files are first converted into binary and then stored. For articles or longer texts , they are stored in CLOB , so that future queries can be updated. Storage and other operations provide great convenience.
CLOB definition
A type used to save files in a database .
Character Large Object
Mapping of SQL type CLOBs in the JavaTM programming language. SQL CLOB is a built-in type that stores a Character Large Object as a column value in a row of a database table. By default, the driver implements Clob objects using the SQL locator(CLOB), which means that the CLOB object contains a logical pointer to the SQL CLOB data rather than the data itself. A Clob object is valid for the duration of the transaction in which it was created.
In some database systems, Text is also used as an alias for CLOB, such as SQL Server
Meaning of BLOB
BLOB (binary large object), binary large object, is a container that can store binary files.
In computers, BLOBs are often the field type used to store binary files in databases.
A BLOB is a large file, typically a picture or a sound file, and due to their size, must be handled in a special way (eg: upload, download or store in a database).
According to Eric Raymond, the main idea of dealing with BLOBs is to let file processors (such as database managers) not care what the file is, but how to deal with it.
However, some experts emphasized that this method of dealing with large data objects is a double-edged sword, and it may cause some problems, such as the storage of binary files that are too large, which will degrade the performance of the database. Storing large multimedia objects in the database is a typical example of application processing BLOB.
Difference between CLOB and BLOB
CLOB uses CHAR to hold data. Such as: save XML documents.
BLOB is to use binary to store data. Such as: save bitmap.
The operation of CLOB in JAVA
In the vast majority of cases, use 2 methods to use CLOB
1 Relatively small, you can use String for direct operations, just treat CLOB as a string type
2 If it is relatively large, you can use getAsciiStream or getUnicodeStream and the corresponding setAsciiStream and setUnicodeStream
read data
ResultSet rs = stmt.executeQuery("SELECT TOP 1 * FROM Test1");
rs.next();
Reader reader = rs.getCharacterStream(2);
insert data
PreparedStatement pstmt = con.prepareStatement("INSERT INTO test1 (c1_id, c2_vcmax) VALUES (?, ?)");
pstmt.setInt(1, 1);
pstmt.setString(2, htmlStr);
pstmt.executeUpdate();
update data
Statement stmt = con.createStatemet();
ResultSet rs = stmt.executeQuery("SELECT * FROM test1");
rs.next();
Clob clob = rs.getClob(2);
long pos = clob.position("dog", 1);
clob.setString(1, "cat", len, 3);
rs.updateClob(2, clob);
rs.updateRow();
A type used to save files in a database .
Character Large Object
Mapping of SQL type CLOBs in the JavaTM programming language. SQL CLOB is a built-in type that stores a Character Large Object as a column value in a row of a database table. By default, the driver implements Clob objects using the SQL locator(CLOB), which means that the CLOB object contains a logical pointer to the SQL CLOB data rather than the data itself. A Clob object is valid for the duration of the transaction in which it was created.
In some database systems, Text is also used as an alias for CLOB, such as SQL Server
BLOB (binary large object), binary large object, is a container that can store binary files.
In computers, BLOBs are often the field type used to store binary files in databases.
A BLOB is a large file, typically a picture or a sound file, and due to their size, must be handled in a special way (eg: upload, download or store in a database).
According to Eric Raymond, the main idea of dealing with BLOBs is to let file processors (such as database managers) not care what the file is, but how to deal with it.
However, some experts emphasized that this method of dealing with large data objects is a double-edged sword, and it may cause some problems, such as the storage of binary files that are too large, which will degrade the performance of the database. Storing large multimedia objects in the database is a typical example of application processing BLOB.
CLOB uses CHAR to hold data. Such as: save XML documents.
BLOB is to use binary to store data. Such as: save bitmap.
In the vast majority of cases, use 2 methods to use CLOB
1 Relatively small, you can use String for direct operations, just treat CLOB as a string type
2 If it is relatively large, you can use getAsciiStream or getUnicodeStream and the corresponding setAsciiStream and setUnicodeStream
read data
ResultSet rs = stmt.executeQuery("SELECT TOP 1 * FROM Test1");
rs.next();
Reader reader = rs.getCharacterStream(2);
insert data
PreparedStatement pstmt = con.prepareStatement("INSERT INTO test1 (c1_id, c2_vcmax) VALUES (?, ?)");
pstmt.setInt(1, 1);
pstmt.setString(2, htmlStr);
pstmt.executeUpdate();
update data
Statement stmt = con.createStatemet();
ResultSet rs = stmt.executeQuery("SELECT * FROM test1");
rs.next();
Clob clob = rs.getClob(2);
long pos = clob.position("dog", 1);
clob.setString(1, "cat", len, 3);
rs.updateClob(2, clob);
rs.updateRow();
Both BLOB and CLOB are large field types, BLOB is stored in binary, and CLOB can directly store text. In fact, the two are interchangeable, or you can directly replace the two with the LOB field. However, in order to better manage the ORACLE database, information such as pictures, files, and music are usually stored in BLOB fields, and the files are first converted into binary and then stored. For articles or longer texts, CLOB is used to store them, which provides great convenience for future queries, updates, storage, and other operations.