6. LOBS
* To read a piece of a LOB. BLOB blob = ((OracleResultSet) rset).getBLOB (1);
byte[] bytes = blob.getBytes (<begin index>, <length>); CLOB clob = ((OracleResultSet) rset).getCLOB (2);
String str = clob.getSubString (<begin index>, <length>); BFILE bfile = ((OracleResultSet) rset).getBFILE (3);
byte[] bytes = bfile.getBytes (<begin index>, <length>);
* To read the LOB content as a stream. BLOB blob = ((OracleResultSet) rset).getBLOB (1);
InputStream input_stream = blob.getBinaryStream ();
input_stream.read (...); CLOB Clob = ((OracleResultSet) rset).getCLOB (1);
Reader char_stream = Clob.getCharacterStream ();
char_stream.read (...); CLOB Clob = ((OracleResultSet) rset).getCLOB (1);
InputStream input_stream = Clob.getAsciiStream ();
input_stream.read (...); BFILE bfile = ((OracleResultSet) rset).getBFILE (1);
InputStream input_stream = bfile.getBinaryStream ();
input_stream.read (...);
* To write a specified amount of data into a LOB. BLOB blob = ((OracleResultSet) rset).getBLOB (1);
byte[] data = ...
int amount_written = blob.putBytes (<begin index>, data); CLOB clob = ((OracleResultSet) rset).getCLOB (1);
String data = ...
int amount_written = clob.putString (<begin index>, data);
* To replace the LOB content from a stream. BLOB blob = ((OracleResultSet) rset).getBLOB (1);
OutputStream output_stream = blob.getBinaryOutputStream ();
output_stream.write (...); CLOB clob = ((OracleResultSet) rset).getCLOB (1);
Writer char_stream = Clob.getCharacterOutputStream ();
char_stream.write (...); CLOB Clob = ((OracleResultSet) rset).getCLOB (1);
OutputStream output_stream = Clob.getAsciiOutputStream ();
output_stream.write (...);
* To get LOB length. long length = blob.length ();
long length = clob.length (); long length = bfile.length ();
* To read a piece of a LOB. BLOB blob = ((OracleResultSet) rset).getBLOB (1);
byte[] bytes = blob.getBytes (<begin index>, <length>); CLOB clob = ((OracleResultSet) rset).getCLOB (2);
String str = clob.getSubString (<begin index>, <length>); BFILE bfile = ((OracleResultSet) rset).getBFILE (3);
byte[] bytes = bfile.getBytes (<begin index>, <length>);
* To read the LOB content as a stream. BLOB blob = ((OracleResultSet) rset).getBLOB (1);
InputStream input_stream = blob.getBinaryStream ();
input_stream.read (...); CLOB Clob = ((OracleResultSet) rset).getCLOB (1);
Reader char_stream = Clob.getCharacterStream ();
char_stream.read (...); CLOB Clob = ((OracleResultSet) rset).getCLOB (1);
InputStream input_stream = Clob.getAsciiStream ();
input_stream.read (...); BFILE bfile = ((OracleResultSet) rset).getBFILE (1);
InputStream input_stream = bfile.getBinaryStream ();
input_stream.read (...);
* To write a specified amount of data into a LOB. BLOB blob = ((OracleResultSet) rset).getBLOB (1);
byte[] data = ...
int amount_written = blob.putBytes (<begin index>, data); CLOB clob = ((OracleResultSet) rset).getCLOB (1);
String data = ...
int amount_written = clob.putString (<begin index>, data);
* To replace the LOB content from a stream. BLOB blob = ((OracleResultSet) rset).getBLOB (1);
OutputStream output_stream = blob.getBinaryOutputStream ();
output_stream.write (...); CLOB clob = ((OracleResultSet) rset).getCLOB (1);
Writer char_stream = Clob.getCharacterOutputStream ();
char_stream.write (...); CLOB Clob = ((OracleResultSet) rset).getCLOB (1);
OutputStream output_stream = Clob.getAsciiOutputStream ();
output_stream.write (...);
* To get LOB length. long length = blob.length ();
long length = clob.length (); long length = bfile.length ();
int fileLength = file.length();
java.io.InputStream fin = new java.io.FileInputStream(file);
java.sql.PreparedStatement pstmt = con.prepareStatement(
"UPDATE Table5 SET stuff = ? WHERE index = 4");
pstmt.setBinaryStream (1, fin, fileLength);
pstmt.executeUpdate();
参照上面JDK帮助文档中的程序仿写一个就可以了!