JDBC call to a stored procedure that takes an array as a parameter
I am trying to call the procedure below using java code, but I am getting a few errors (mainly for type conversions). I messed something up, can someone take a look at it.
This is the first time I do this.
A little help will be great.
good:
DECLARE
car__details_tab car__details_tab_type := NEW car__details_tab_type();
car_id number_tab_type;
car_error_tab car__error_tab_type := new car__error_tab_type();
car_purchase_id NUMBER;
BEGIN
car__details_tab.extend;
car__details_tab(car__details_tab.count) := car__details_type(null,
null
,null
,null
,null
);
car__details_tab(car__details_tab.COUNT).model_id := AW0;
car__details_tab(car__details_tab.COUNT).brand := 'LAM';
car__details_tab(car__details_tab.COUNT).version := 1;
car__details_tab(car__details_tab.COUNT).type := 'Sedan';
pckg.ins_trade_details(car__details_tab => car__details_tab
,car_purchase_id => 101
,user => 'Test'
,car_id_tab => car_id
,car_error_tab => car_error_tab);
DBMS_OUTPUT.PUT_LINE(car_purchase_id);
IF car_error_tab.EXISTS(1)
THEN
FOR i IN 1 .. car_error_tab.COUNT
LOOP
dbms_output.put_line(car_error_tab(i).model_id);
dbms_output.put_line(car_error_tab(i).version);
dbms_output.put_line(car_error_tab(i).version);
dbms_output.put_line(car_error_tab(i).error_text);
END LOOP;
END IF;
Java code
public void save(String DataSource,int Id,String username,String[] car__details_tab_type) throws SQLException{
Connection con = getConnection(DataSource);
CallableStatement cs= con.prepareCall({call pckg.save_details(?,?,?,?,?)});
Object[] project1 = new Object[]{AWO,"LAM,1,"SEDAN"};
Object[] project2 = new Object[]{AWO,"LAM,1,"SEDAN"};
StructDescriptor projectTypeDesc = StructDescriptor.createDescriptor("CAR__DETAILS_TAB_TYPE", con);
STRUCT structProject1 = new STRUCT(projectTypeDesc, con, project1);//THIS IS WHERE I GET THE ERROR
STRUCT structProject2 = new STRUCT(projectTypeDesc, con, project2);
STRUCT[] structArrayOfProjects = {structProject1,structProject2};
ArrayDescriptor projectTypeArrayDesc = ArrayDescriptor.createDescriptor("CAR__DETAILS_TAB_TYPE", con);
ARRAY arrayOfProjects = new ARRAY(projectTypeArrayDesc, con, structArrayOfProjects);
cs.setArray(1, details);
cs.setInt(2, Id);
cs.setString(3, username);
cs.registerOutParameter(4, java.sql.Types.ARRAY);
cs.registerOutParameter(5, java.sql.Types.ARRAY);
cs.execute();
}
MISTAKE
java.sql.SQLException: inconsistent java and sql object types
0
fiddle
source
to share
No one has answered this question yet
See similar questions:
3
3
1
or similar:
1504
784
679
461
416
197
4
3
1
0