I am trying to call a stored function in Java. Function has no package, it's placed under user (schema) USER and returns a cursor. I tried twoways to call it and none of these works.
First one
Query query = coreDao.getEntityManager().createNativeQuery("{call USER.gen_rephead_sm_task_report(?, ?) }");
query.setParameter(1, dateFrom);
query.setParameter(2, dateTo);
List<?> queryResult = query.getResultList();
I got a not a procedure or not defined
I also tried this approach with
select gen_rephead_sm_task_report(?, ?) from dual
as a createNativeQuery parameter but with the same result.
Second one
Connection connection = dataSource.getConnection();//javax.sql.DataSource
CallableStatement statement = connection.prepareCall("{? = call USER.gen_rephead_sm_task_report(?, ?) }");
statement.registerOutParameter(1, OracleTypes.CURSOR);//oracle.jdbc.OracleTypes
statement.setDate(2, new java.sql.Date(dateFrom.getTime()));
statement.setDate(3, new java.sql.Date(dateTo.getTime()));
statement.executeQuery();
ResultSet set = ((OracleCallableStatement) statement).getCursor(1);
I got the ClassCastException
on the last line (obviously OracleCallableStatement doesn't implement the CallableStatement). So which types shoud I use here?