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
//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
//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