Sending empty sql Array into oracle procedure

Maksim Vasilovich :

I'm trying to send sql.Array into procedure but somehow it gets empty inside of oracle procedure.

My java code that fill sql.Array with data and try to send it into procedure.

         oracle.jdbc.OracleConnection connection = (OracleConnection) JdbcConnection.getInstance().createConnection();
            String [] name = new String[]{"20206643799002684001","20206643799002684001"};
            ArrayDescriptor arrDec = ArrayDescriptor.createDescriptor("ARRAY_VARCHAR2",connection.unwrap(oracle.jdbc.OracleConnection.class));
            Array arr = new ARRAY(arrDec,connection.unwrap(oracle.jdbc.OracleConnection.class),name);
            OracleCallableStatement callableStatement = connection.prepareCall("{call bss_acc.ACC_STATEMENT(?,?,?,?)}");
            callableStatement.setDate(1,date);
            callableStatement.setDate(2,dateL);
           ((OracleCallableStatement)callableStatement).setARRAY(3,arr);
            callableStatement.setString(4,this.branchId);
            callableStatement.execute();

And in procedure I put log in order to see what value I'm getting after executing of this procedure. And always I'm getting empty array element which shows up in this procedure.

procedure ACC_STATEMENT
(
i_begin_date date,
i_end_date date,
i_ids array_varchar2,
i_mfo varchar2
)
is
o_ext_acc varchar2(20);
o_beginRest number;
o_endRest number;
o_name varchar2(100);
o_rest number;
o_type varchar2(100);

begin

FOR i IN 1.. i_ids.count LOOP
o_ext_acc := i_ids(i);

-- test

RAISE_ERROR(20000, 'o_ext_acc -' ||o_ext_acc);

And I see after executing this error with empty o_ext_acc to show up this message I redirect it into other procedure

java.sql.SQLException: ORA-20000: 
20000:  o_ext_acc -
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:447)
  at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
  at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:951)
  at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:513)
  at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:227)
  at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
  at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:205)
  at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:1043)
  at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1336)
  at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3613)
  at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3714)
  at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4755)
  at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1378)
  at com.uzb.bank.demo.service.impl.GenerateIntoXmlImpl.accountStatement(GenerateIntoXmlImpl.java:414)
  at com.uzb.bank.demo.controller.Controller.accountStatement(Controller.java:72)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498)
  at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
  at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
  at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:892)
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797)
  at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1039)
  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
  at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
  at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)

UPD When I put debug mode in order to see what's going on with arr then I have noticed this data.Which means array dosn't take value from it and it show up question mark instead of it.

enter image description here

UPD

I know that I'm using sql array and changed it into oracle.sql.Array and tried to create with following code but it again runs empty.

 oracle.jdbc.OracleConnection connection = (OracleConnection) JdbcConnection.getInstance().createConnection();
            String [] name = new String[]{"20206643799002684001","20206643799002684001"};
            oracle.sql.ARRAY a = connection.createARRAY("ARRAY_VARCHAR2",name);
            CallableStatement callableStatement = connection.prepareCall("{call bss_acc.ACC_STATEMENT(?,?,?,?)}");
            callableStatement.setDate(1,date);
            callableStatement.setDate(2,dateL);
           ((OracleCallableStatement)callableStatement).setArray(3,a);
            callableStatement.setString(4,this.branchId);
            callableStatement.execute();

UPD 3

        oracle.jdbc.OracleConnection connection = (OracleConnection) JdbcConnection.getInstance().createConnection();
        String [] name = new String[]{"20206643799002684001","20206643799002684001"};
        oracle.sql.ArrayDescriptor arrayDescriptor = new ArrayDescriptor("ARRAY_VARCHAR2",connection);
        oracle.sql.ARRAY a = new ARRAY(arrayDescriptor,connection,name);
        OracleCallableStatement callableStatement = (OracleCallableStatement) connection.prepareCall("{call bss_acc.ACC_STATEMENT(?,?,?,?)}");
        callableStatement.setDate(1,date);
        callableStatement.setDate(2,dateL);
        callableStatement.setARRAY(3,a);
        callableStatement.setString(4,this.branchId);
        callableStatement.execute();

UPD 4

After send empty oracle.sql.Array it gives error from my procedure and print part it shows up empty sql array element

java.sql.SQLException: ORA-20000:

20000: o_ext_acc:/empty sending array element here is empty. Here should be element of sending array/ORA-06512: на "IBS.RAISE_ERROR", line 74 ORA-06512: на "IBS.BSS_ACC", line 30 ORA-06512: на line 1

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:447) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396) at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:951) at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:513)

UPD 5

I modify it procedure

FOR i IN 1.. i_ids.count LOOP o_ext_acc := i_ids(i);

-- test

RAISE_ERROR(20000, 'date:' || i_begin_date || 'accountElement ' || o_ext_acc);

then I got following error where I can see date but there is empty o_ext_acc

java.sql.SQLException: ORA-20000: 20000: date:02.09.19accountElement

The prolbem I can't catch sending oracle.jdbc.Array in procedure somehow it comes from jdbc into oracle procedure like empty array and elements is empty

I run this procedure from Oracle and it works fine without errors

Maksim Vasilovich :

After two days of search There was main problem is datumnArray was ???. This means oracld db and jdbc was not match with their characterset.After adding this code.

 String s1 = new String(account.get(0).getBytes(), Charset.forName("ISO-8859-1"));
                String [] name = new String[]{s1};
                //oracle.sql.ArrayDescriptor arrayDescriptor = new ArrayDescriptor("ARRAY_VARCHAR2",connection);
                oracle.sql.ARRAY a = connection.createARRAY("ARRAY_VARCHAR2", name);

enter image description here

and adding This lib into maven

<dependency>
        <groupId>com.oracle</groupId>
        <artifactId>orai18n</artifactId>
        <version>11.1.0.7.0</version>
    </dependency>

This worked for me. I think both of them play crucial way to solve the problem.At the begining of the was following picture.

enter image description here

Guess you like

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