You need to create a StructDescriptor and then a STRUCT object that you can then set.
An alternative to the PreparedStatementSetter is to use an AbstractSqlTypeValue for this feature, and put that in the Map of in-parameters.
Here is an example of a StoredProcedure implementation passing in a STRUCT:
Code:
private class AddItem extends StoredProcedure {
public AddItem(JdbcTemplate jdbcTemplate) {
super(jdbcTemplate, "item_package.add_item");
declareParameter(new SqlParameter("item", OracleTypes.STRUCT, "ITEM_TYPE"));
declareParameter(new SqlOutParameter("return", Types.NUMERIC));
compile();
}
public Number execute(final TestItem testItem) {
SqlTypeValue value = new AbstractSqlTypeValue() {
protected Object createTypeValue(Connection conn, int sqlType, String typeName) throws SQLException {
StructDescriptor itemDescriptor = new StructDescriptor(typeName, conn);
Struct item = new STRUCT(itemDescriptor, conn,
new Object[] {
testItem.getId(),
testItem.getDescription(),
new java.sql.Date(testItem.getExpirationDate().getTime())
});
return item;
}
};
Map inParam = new HashMap(1);
inParam.put("item", value);
Map outValues = execute(inParam);
return (Number)outValues.get("return");
}
}
The type declaration used for this example is:
Code:
CREATE OR REPLACE TYPE item_type AS OBJECT(id INTEGER, descr VARCHAR(50), exp_date DATE);