The Blob in Java and the explanation of CLOB

Source: Internet
Author: User
Tags stmt

CLOB definition

A type in the database that is used to save the file.

Character Large Object

The SQL type CLOB the mapping relationship in the JAVATM programming language. SQL CLOB is a built-in type that stores character large objects (Character Large object) as a column value in a row of a database table. By default, the driver uses SQL Locator (CLOB) to implement the CLOB object, which means that the CLOB object contains a logical pointer to the SQL CLOB data instead of the data itself. The Clob object is valid during the transaction during which it was created.

In some database systems, text is also used as an alias for CLOB, such as SQL Server

What the blob means

BLOB (Binary large object), binary large, is a container that can store binary files.

In computers, blobs are often the type of field used in a database to store binary files.

A blob is a large file, a typical blob is a picture or a sound file, and due to its size, it must be handled in a special way (for example, uploading, downloading, or storing to a database).

According to Eric Raymond, the main idea of dealing with blobs is to let a file processor (such as a database manager) ignore what the file is, but rather care about how to handle it.

But there are also experts who stress that the way to handle big data objects is to double-edged swords, which may cause problems such as storing binary files too large, which can degrade the performance of the database. Storing large multimedia objects in a database is a typical example of application processing blobs.

The difference between CLOB and blobs

CLOB uses char to save data. such as: Save the XML document.

BLOBs are used to store data in binary. such as: Save Bitmap.

The operation of Clob inside Java

In the vast majority of cases, using CLOB in 2 ways

1 relatively small, can be directly manipulated by string, Clob as a string type can be

2 If larger, you can use Getasciistream or getunicodestream and corresponding Setasciistream and Setunicodestream.

  Reading data

ResultSet rs = stmt.executequery ("Select TOP 1 * from Test1");

Rs.next ();

Reader reader = Rs.getcharacterstream (2);

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

The Blob in Java and the explanation of CLOB

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.