In Oracle SQL I have a type:
CREATE OR REPLACE type address_type
AS
OBJECT
(
Street VARCHAR2(100),
Road VARCHAR2(100),
Town VARCHAR2(100),
County VARCHAR2(100) );
This is used for a function, the function uses the ADDRESS_TYPE to take an answer as a parameter and returns an integer:
create or replace FUNCTION ADD_ADDRESS_FUNC(
New_Address IN Address_Type )
RETURN INTEGER
AS
AddressID INTEGER;
BEGIN
AddressID := ADDRESS_SEQ.NEXTVAL;
INSERT
INTO Address VALUES
(
AddressID,
New_Address.Street,
New_Address.Road,
New_Address.Town,
New_Address.County
);
DBMS_OUTPUT.PUT_LINE(AddressID);
RETURN AddressID;
END;
In my Java classes I have all connections etc & I can access other procs & functions but not this one which takes the Address object. In Java I create an Address object a with 4 strings, surely I can just pass this as second argument below:
Address a = new Address("Address 1", "Address 2", "Town", "County");
CallableStatement stmt = conn.prepareCall( "begin ? := ADD_ADDRESS_FUNC(?);end;" );
stmt.registerOutParameter(1, Types.CHAR);
stmt.setObject(2, a);
stmt.execute ();
int memberID = stmt.getInt(1);`
The error message says invalid column index and it is breaking down at the setObject call. If it were a string it would be fine but the Address object isn't working. Any help appreciated, thanks in advance
Structcapability that lets you map Java objects to SQL objects. I've never done this so I'm posting this as a comment instead of an answer since I can't give you a lot of detail.STRUCTobject/ResultSet object as you wish. It has some methods that gets called when query.listResults() or similar is invoked.