Call oracle stored procedure with oracle object parameter

Gog1nA :

I upgraded oracle and ojdbc versions from 11.1.0.2 to 12.1.0.2. I want to give an array of oracle object types as a parameter to an oracle procedure. This procedure takes 2 varchar2 parameters on oracle side. For example, I am sending 3 objects as an array of key-value pairs and oracle accepts these objects. My problem is that the parameters (of varchar2 type) are null, when calling my procedure.

Here is the code I have tried.

OracleConnection oraconn = conn.unwrap(OracleConnection.class);
Struct[] paramStructArray = new Struct[3];
paramStructArray[0] = oraconn.createStruct("KEY_VALUE_ENTRY",new Object[]{"key1","value1"});
paramStructArray[1] = oraconn.createStruct("KEY_VALUE_ENTRY",new Object[]{"key2","value2"});
paramStructArray[2] = oraconn.createStruct("KEY_VALUE_ENTRY",new Object[]{"key3","value3"});
Array array = oraconn.createOracleArray("KEY_VALUE_MAP", paramStructArray);

CallableStatement cstmt = getStatement(Statement.REGISTER_REQUEST);
cstmt.setString(1, requestId);
cstmt.setArray(2, array);
cstmt.execute();

This is my java code and here is also my oracle objects


CREATE OR REPLACE TYPE "KEY_VALUE_ENTRY"  AS
OBJECT (
  key VARCHAR2(32),
  val VARCHAR2(2048)
);


CREATE OR REPLACE TYPE "KEY_VALUE_MAP"    AS
TABLE OF key_value_entry;

and my procedure

PROCEDURE register_request_(p_request_id IN varchar2
                             ,p_params     IN key_value_map) AS
  BEGIN
    IF p_params IS NOT NULL THEN
      INSERT INTO test_table
        (request, NAME, VALUE)
        SELECT test_seq.nextval
              ,t.key
              ,t.val
          FROM TABLE(CAST(p_params AS key_value_map)) t;
      COMMIT;
  END IF;
  EXCEPTION
    WHEN OTHERS THEN
      RAISE;
  END;

I am taking 3 KEY_VALUE_ENTRY type objects on oracle side but this objects' key and val fields are both null. I can not figure out what I am doing wrong.

Gog1nA :

There was Encoding problem, in which java gives and oracle takes this values, after adding orai18n.jar in my classpath everything works fine

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=122111&siteId=1