I don't understand what you're trying to do here.
It sounds like you're trying to build a generic "accept any query, return any result set" process. Which is generally a bad idea.
But I'm still not seeing why you
need the any* types. You can have the Java return to a sys_refcursor:
create or replace and resolve java source named refcur as
import java.sql.*;
import java.io.*;
import oracle.jdbc.*;
/*
* Mapping REF CURSOR to java.sql.Resultset
*/
public class refcur
{
/*
* Procedure returning a REF CURSOR via OUT parameter
*/
public static void refcurproc (ResultSet rs[])
throws SQLException
{
Connection conn = null;
conn = DriverManager.getConnection("jdbc:oracle:kprb:");
((OracleConnection)conn).setCreateStatementAsRefCursor(true);
Statement stmt = conn.createStatement();
((OracleStatement)stmt).setRowPrefetch(1);
ResultSet rset = stmt.executeQuery("select * from EMP order by empno");
rs[0] = rset;
// fetch one row
if (rset.next())
{
System.out.println("Ename = " + rset.getString(2));
}
}
/*
* Function returning a REF CURSOR
*/
public static ResultSet refcurfunc ()
throws SQLException
{
Connection conn = null;
conn = DriverManager.getConnection("jdbc:oracle:kprb:");
((OracleConnection)conn).setCreateStatementAsRefCursor(true);
Statement stmt = conn.createStatement();
((OracleStatement)stmt).setRowPrefetch(1);
ResultSet rset = stmt.executeQuery("select * from EMP order by empno");
// fetch one row
if (rset.next())
{
System.out.println("Ename = " + rset.getString(2));
}
return rset;
}
}
/
show errors;
create or replace package refcur_pkg as
type EmpCurTyp IS REF CURSOR;
function rcfunc return sys_refcursor;
procedure rcproc (rc OUT sys_refcursor);
end refcur_pkg;
/
show errors;
create or replace package body refcur_pkg as
procedure rcproc(rc OUT sys_refcursor)
as language java
name 'refcur.refcurproc(java.sql.ResultSet[])';
function rcfunc return sys_refcursor
as language java
name 'refcur.refcurfunc() returns java.sql.ResultSet';
end refcur_pkg;
/
show errors;
---
--- A demo PL/SQL for calling the Java procedure/function
--- then processing the refcursor.
--- A Java app would retrieve the result set from the Ref Cursor
---
set serveroutput on
call dbms_java.set_output(50000);
declare
employee emp%ROWTYPE;
rc sys_refcursor;
begin
dbms_output.put_line(' ** Calling REF CURSOR PROCEDURE' );
refcur_pkg.rcproc(rc);
---
--- Alternatively the refcurfunc could be called as follows
--- rc = refcur_pkg.rcfunc();
---
LOOP
fetch rc into employee;
exit when rc%notfound;
dbms_output.put_line(' Name = ' || employee.ENAME ||
' Department = ' || employee.DEPTNO);
end loop;
close rc;
end;
/
show errors;
** Calling REF CURSOR PROCEDURE
Ename = SMITH
Name = ALLEN Department = 30
Name = WARD Department = 30
Name = JONES Department = 20
Name = MARTIN Department = 30
Name = BLAKE Department = 30
Name = CLARK Department = 10
Name = SCOTT Department = 20
Name = KING Department = 10
Name = TURNER Department = 30
Name = ADAMS Department = 20
Name = JAMES Department = 30
Name = FORD Department = 20
Name = MILLER Department = 10
OK, so the PL/SQL client needs to know the shape of the result set.
But my understanding is you have DB1 send a query to DB2 via Java. Then get the results back. So surely DB1 has some idea what it's asking for? Otherwise how can it construct the query?