Databases Reference
In-Depth Information
5.6 Handling large objects
JDBC provides different classes to support BLOB, CLOB, and XML values.
BLOB
A BLOB value can be used to store the binary large value. A BLOB object can be
created and populated using the way shown in Example 5-14.
Example 5-14 Creating a BLOB value
String data=new String("jdbc");
byte[] byteArray=data.getBytes();
java.sql.Blob
blobData=com.ibm.db2.jcc.t2zos.DB2LobFactory.createBlob(byteArray);
BLOB implementation in DB2 JDBC universal driver does not support any
constructor function to create the BLOB object. So, it is not possible to create a
BLOB object using a new operator.
The value of the BLOB type parameter can be set using the following
PreparedStatement setter methods:
setBytes
SetBinaryStream
The BLOB value from the ResultSet object can be retrieved using the following
ResultSet getter methods:
getBytes
getBinaryStream
CLOB and DBCLOB
A CLOB value can be used to store the character large value. A CLOB object can
be created using a way similar to the way we created a BLOB object.
Example 5-15 shows how to create a CLOB value.
Example 5-15 Creating a CLOB value
String xsdData = new String("jdbc");
java.sql.Clob clobData =
com.ibm.db2.jcc.t2zos.DB2LobFactory.createClob(xsdData);
The parameter value of type CLOB can be set using the following setter methods
of PreparedStatement object:
setString
Search WWH ::




Custom Search