How to Pass multiple Values in objType parmeter

414 Views Asked by At

How to pass multiple values in objType field to a method parameter

Currently i'm storing single row in objType field and passing that as an input to an oracle sp, now i need to store and pass multiple rows in objType. How to achieve that? I've tried creating objType like multidimensional one: Object[] objType = new Object[3][3], it doesn't help. Please see my sample code below and help.

Object[] objType = new Object[3];
objType[0] = new Integer(lineNo);
objType[1] = new String(itemCode);
objType[2] = new Integer(ORDER_QTY));


structs[index]=conn.createStruct("XXHDB_REC", objType);
        Array reportsArray = ((OracleConnection)     

conn).createOracleArray("XXHDB_TBL_TYPE", structs);

//Input to oracle package
oracleCallableStmt.setArray(4, reportsArray);

I need to store 'n' of rows with fixed 3 columns. [n][3].

Stored Proc Definition:
create_booking(p_reservation_id  => p_reservation_id, 
p_Hybris_Cust_nbr => p_Hybris_Cust_nbr,
p_cust_nbr        => p_cust_order_no,
p_group           => j.GROUP_ID,
p_order_lines     => v_rec) --> this is the input field
1

There are 1 best solutions below

3
AudioBubble On

Your example code Object[] objType = new Object[3][3] does not work as objType has the wrong type, it should be Object[][] objType = new Object[n][3]. However I strongly recommend to not use Object as type if you know the values you want to store, instead you could use some sort of container for them like:

class Container {
    private Integer lineNo;
    private String itemCode;
    private Integer ORDER_QTY;

    // rest omitted
}

And then use this as your type your array or whatever you want to use. Container[] objType = new Container[n];.