Using JSP to manipulate Oracle's CLOB fields

Source: Internet
Author: User
Js|oracle Clob is generally used to store large Guangxi, if it is a 2-in-system file generally with a blob.
Suppose Col2 is CLOB:
Write operation:

String sql = "INSERT into tb_commendtemp (col1,col2) VALUES (' 111 ',?)";
string s = "long text";
StringBufferInputStream sbin = new StringBufferInputStream (s);
PreparedStatement PS = query.getprestmt (SQL);
Ps.setasciistream (1,sbin,s.length ());
int i = Ps.executeupdate ();
Ps.close ();
Sbin.close ();
if (i>0) OK;
If it's a binary file, write it in FileInputStream.

When you read it, just
Rs.getasciistream ();
Rs.getunicodestream ();
Rs.getbinarystream ();
Look at their names to see what kind of data flow it is.

If you are storing binary files, such as graphics, executing files, compressed files, preferably blob insurance.
Write and read also use binary stream,
Datainputstrean and Datoutputstream. Sometimes it can be done with Unicode characters, but
No insurance. If it is text, use CLOB and long. Read and Write
Buffreedreader and PrintWriter are more convenient.


To display text and images from the program at the same time on a Web page, this technology is currently in the country
Can be worth 1 million.
Since browsers want to display both HTML documents and image documents at the same time, you are not currently in the country
Find that you want to use the server push technology. You want to think about the e-mail document header, is compound, put
The data can be used for base 64 encoding to display text and pictures at the same time with a specific document type. But browsers are still not doing it.

BLOB: binary, if exe,zip
CLOB: Single-byte code, such as a general text file.
Nlob: Multi-Byte code, such as a file in UTF format.

If the formatted file is word,execl and so on if you want to keep the formatting from being corrupted, it's best to use a blob
method, which is similar to storing in the original byte, the disadvantage of course is low efficiency (slow) operation.

Operation Clob, others can look at me above the writing and reading examples, just pay attention to
Write Pstmt.setbinarystream () into Rs.setasciistream ();
Read Pstmt.getbinarystream () into Rs.getbinarystream ();

Use reader instead of Datainuputstream when reading from file to stream

Related Article

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.