Read an ARRAY from a STRUCT returned by a stored procedure

后端 未结 4 1904
臣服心动
臣服心动 2021-02-09 13:35

In the database are three Oracle custom types (simplified) as follows:

create or replace TYPE T_ENCLOSURE AS OBJECT(
  ENCLOSURE_ID      NUMBER(32,0),
  ENCLOSUR         


        
4条回答
  •  耶瑟儿~
    2021-02-09 14:28

    I Just share the logic which worked for me. You can try this to retrieve ARRAY response from PL/SQL to Java.

    CallableStatement callstmt = jdbcConnection.prepareCall("{call PROCEDURE_NAME(?, ?)}");
    callstmt.setArray(1, array);
    callstmt.registerOutParameter(2,Types.ARRAY, );
    // Do all execute operations
        Array arr = callstmt.getArray(1);
                if (arr != null) {
                   Object[] data = (Object[]) arr.getArray();
                   for (Object a : data) {
                       OracleStruct empstruct = (OracleStruct) a;
                       Object[] objarr = empstruct.getAttributes();
                        r = new (objarr[0].toString(), objarr[1].toString());
                       System.out.println("Response-> : "+ r.toString());
                   }
                }
    

提交回复
热议问题