I have a stored procedure which returns sys_refcursor and I am trying to fetch the cursor from java using JDBC.
plsql stored procedure
create or replace procedure my_proc(p_deptno IN number,p_emp_no IN varchar2
, p_cursor OUT SYS_REFCURSOR)
is
begin
open p_cursor FOR
select *
from emp
where deptno = p_deptno and emp_number=p_emp_no;
end proc;
/
java code
callablestatement = connection.prepareCall("{cal my_proc(?,?,?)} ");
callablestatement.setInt(1, param1);
callablestatement.setString(2, param2);
callablestatement.registerOutParameter(3, OracleTypes.CURSOR);
callablestatement.execute();
resultSet = ((OracleCallableStatement)callablestatement).getCursor(4);
while (resultSet.next()) {
<classname> = mapList(resultSet);
logger.info(resultSet.getString(1));
}
When I execute the above I am getting the following execeptions
java.lang.NullPointerException at callablestatement.execute();
and
Non supported SQL92 token at position: 3: cal
I have resolved the issue by using a function with the same code as in the procedure and it has resolved my issue.
And I called my function using the following manner.
Thanks