Java Operations Oracle's BLOB,CLOB data

Source: Internet
Author: User

I. Distinctions and definitions

Long : variable long string data, longest 2g,long with VARCHAR2 column, can store long text up to one long column in a table
  Long RAW: variable Long binary data, up to 2G
  CLOB: character large object CLOB used to store single-byte character data
  NCLOB: used to store multibyte character data
  BLOB: used to store binary data
  BFILE: binary data stored in a file, the data in this file can only be read-only. However, the file is not included in the database.

bfile Field The actual file is stored in the file system, and the field stores the file locator pointer. bfile is read-only to Oracle and does not participate in transactional control and data recovery.
  
Clob,nclob,blob are internal lob (Large Object) type, maximum 4G, no long can have only one column limit

Which data types are best used to save pictures, text files, and Word files?
--blob best, long Raw is also good, but long is the type that Oracle will discard, so it is recommended to use BLOBs.

Second, Operation 1, get

Blob

Java code
  1. //get a database connectionConnection con =connectionfactory.getconnection (); Con.setautocommit (false); Statement St=con.createstatement (); //no "for update" requiredResultSet rs = st.executequery ("Select Blobattr from Testblob where id=1"); if(Rs.next ()) {Java.sql.Blob Blob= Rs.getblob ("blobattr"); InputStream instream=Blob.getbinarystream (); //data is read out and needs to be returned, the type is byte[]data =New byte[Input.available ()];           Instream.read (data);       Instream.close ();       } instream.close ();       Con.commit ();    Con.close (); 

2. Putblobjava Code
  1. //get a database connectionConnection con =connectionfactory.getconnection (); Con.setautocommit (false); Statement St=con.createstatement (); //insert an empty object Empty_blob ()St.executeupdate ("INSERT into Testblob (ID, NAME, blobattr) VALUES (1," Thename ", Empty_blob ())"); //Lock the data row for updates, and note the "for Update" statementResultSet rs = st.executequery ("Select Blobattr from Testblob where id=1 for update"); if(Rs.next ()) {//cast to Oracle.sql.BLOB after getting Java.sql.Blob objectOracle.sql.BLOB BLOB = (Oracle.sql.BLOB) rs.getblob ("Blobattr"); OutputStream OutStream=Blob.getbinaryoutputstream (); //data is an incoming byte array, defined by: byte[] DataOutstream.write (data, 0, data.length);       } outstream.flush ();       Outstream.close ();       Con.commit ();   Con.close (); 

Java Operations Oracle's BLOB,CLOB data

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.