skip to main content
DataDirect Connect Drivers : Oracle Driver : Data Types : Using Collection Data Types : OBJECT
  
OBJECT
The Oracle OBJECT data type maps to the JDBC STRUCT data type. To use this data type as a parameter, the parameter value must be created using the createStruct() method of the Connection interface. See JDBC Support in the DataDirect Connect Series for JDBC Reference for more information about this method.
Note: The OBJECT data type is not supported for bulk load operations.
If you require more accurate metadata information for this data type, set the CatalogOptions connection property to 8. See the description of CatalogOptions in Connection Properties for details.
Example A: Selecting Data From an Object

Statement st = connection.createStatement();
ResultSet resultSet = st.executeQuery(
"SELECT object_col FROM complex_type_table");

// Loop through the result set and retrieve the objects
while(resultSet.next()) {

// Get the row into java.sql.STRUCT
java.sql.Struct mystruct =
(java.sql.Struct)(resultSet.getObject(1));

// Get the individual field values for the object
Object cols[] = mystruct.getAttributes();
}
Example B: Inserting Data into an Object

Object objArray[] = new Object[4];
String name = "Morrisville";
String state = "North Carolina";
String code = "27560";
java.math.BigDecimal densityint = new java.math.BigDecimal (4);
objArray[0] = name;
objArray[1] = state;
objArray[2] = code;
objArray[3] = densityint;

// Construct the Struct
java.sql.Struct colStruct = connection.createStruct(
"CITY_OBJECT", objArray);

PreparedStatement ps = connection.prepareStatement(
"INSERT INTO complex_type_table (object_col) VALUES (?)");

// Bind the STRUCT representing the object to be inserted
ps.setObject(1, colStruct, java.sql.Types.STRUCT);
ps.executeUpdate();
ps.close();