Java Reference
In-Depth Information
Both Blob and Clob objects provide methods for materializing the object's value on
the client, for getting the length of the object, and for performing searches within the
object's value.
The JDBC 3.0 API Extensions add methods to alter the values of BLOBS and CLOBS
directly, using these methods:
 
Blob.setBytes()
 
Clob.setString()
A JDBC Array object materializes the SQL ARRAY it represents as either a result set
or a Java array.
For example, after retrieving the SQL ARRAY value in the column Meds as a
java.sql.Array object, the following code fragment materializes the ARRAY value on
the client. It then iterates through Medications, the Java array that contains the
elements of the SQL ARRAY value.
ResultSet rs = stmt.executeQuery(
"SELECT MEDS FROM Patients WHERE SSN = 123-45-6789");
while (rs.next()) {
Array Medications = rs.getArray("MEDS");
String[] meds = (String[])Medications.getArray();
for (int i = 0; i < meds.length; i++) {
. . . // code to display medications
}
}
The ResultSet method getArray returns the value stored in the column MEDS of the
current row as the java.sql.Array object Medications, as shown here:
Array Medications = rs.getArray("MEDS");
The variable Medications contains a locator, which means that it is a logical pointer to
the SQL ARRAY on the server; it does not contain the elements of the ARRAY itself.
In the following line, getArray is the Array.getArray method, returning a Java Object
that is cast to an array of String objects before being assigned to the variable meds.
String[] meds = (String[])Medications.getArray();
Thus, the Array.getArray method materializes the SQL ARRAY elements on the client
as an array of String objects we can iterate through and display.
Creating User Defined Data Types
Search WWH ::




Custom Search