How to pass a refcursor to a java stored proc

Hi all,
Please forgive me as I am new to Java and JDeveloper....
I want to pass a refcursor to a java stored proc. Does anyone know how to accomplish this?
Thanks,
dayneo

Hi,
As Avi has indicated, you can map ref cursor to java.sql.ResultSet
here are Call Specs and a code snippet from chapter 3 in my book.
procedure rcproc(rc OUT EmpCurTyp)
as language java
name 'refcur.refcurproc(java.sql.ResultSet[])';
function rcfunc return EmpCurTyp
as language java
name 'refcur.refcurfunc() returns java.sql.ResultSet';
* 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;
Kuassi

Similar Messages

  • How to pass XMLType as parameters to Java stored procs ?

    How to pass XMLType as parameters to Java stored procs ?
    ORA-00932: inconsistent datatypes: expected an IN argument at position 1 that is an instance of an Oracle type convertible to an instance of a user defined Java class got an Oracle type that could not be converted to a java class
    Java stored proc -->
    CREATE or replace FUNCTION testJavaStoredProcMerge( entity xmltype,event xmltype ) RETURN VARCHAR2 AS LANGUAGE JAVA
    NAME 'XDBMergeOp.merge(org.w3c.dom.Document,org.w3c.dom.Document) return java.lang.String';
    PL/SQL -->
    declare
    theQuote VARCHAR2(50);
    entity xmltype;
    event xmltype;
    begin
    entity := xmltype('<Quote><Fields><Field1>f1</Field1></Fields></Quote>');
    event := xmltype('<Quote><Fields><Field2>f2</Field2></Fields></Quote>');
    theQuote := testJavaStoredProcMerge(entity,event);
    dbms_output.put_line(theQuote);
    end;
    Java class -->
    public class XDBMergeOp {
    public static String merge(Document entity, Document event) throws Exception {
    return ...
    Thanks in advance.

    I think you'll need to use XMLType and then extract the DOM inside java..
    create or replace package SAXLOADER
    as
      procedure LOAD(P_PARAMETERS XMLTYPE, P_DATASOURCE BFILE);
    end;
    create or replace package body SAXLOADER
    as
    procedure LOAD(P_PARAMETERS XMLTYPE, P_DATASOURCE BFILE)
    AS
    LANGUAGE JAVA
    NAME 'com.oracle.st.xmldb.pm.saxLoader.SaxProcessor.saxLoader ( oracle.xdb.XMLType, oracle.sql.BFILE)';
    end;
      public static void saxLoader(XMLType parameterSettings, BFILE dataSource)
      throws Exception {
        Document parameters = parameterSettings.getDocument();
        SaxProcessor app = new SaxProcessor(parameters);
        app.processXMLFile(dataSource);
      Edited by: mdrake on Apr 6, 2009 11:28 AM

  • How to pass Table name as argument in Stored Proc

    Hi ,
    I have a requirement wherein the table name has to be passed as an argument of SP and the output should be the count from that table based on some filter condition.
    Something like this:
    create or replace procedure Testing(p_table varchar2,p_count OUT integer) AS
    begin
    select count(1) into p_count from p_table;
    end;
    Getting the error on running above code:
    PL/SQL: ORA-00942: table or view does not exist
    Please let me know how can we do this?
    Thanks.

    Example :SQL> create or replace procedure Testing(
      2     p_table varchar2,
      3     p_count OUT integer) AS
      4  begin
      5     execute immediate 'select count(1) from '||p_table
      6             into p_count;
      7  end;
      8  /
    Procedure created.
    SQL> var n1 number;
    SQL> exec Testing('user_objects',:n1);
    PL/SQL procedure successfully completed.
    SQL> print n1
            N1
            37
    SQL>

  • How to publish a Java Stored proc....

    Hi,
    I wrote the following Java code and loaded it into Oracle 8i, as Java stored procs.
    public class EmployeeStruct
    public int EmployeeNum;
    public String EmployeeName;
    public String Designation;
    and
    import java.sql.*;
    import java.io.*;
    import oracle.jdbc.driver.*;
    public class InsertData
    public static InsertEmployee(EmployeeStruct eps) throws SQLException
    Connection conn =
    DriverManager.getConnection("jdbc:default:connection:");
    String sql = "INSERT INTO EMPLOYEE_TABLE VALUES (?, ?, ?)";
    try
    PreparedStatement pstmt = conn.prepareStatement(sql);
    pstmt.setInt(1, eps.EmployeeNum);
    pstmt.setString(2, eps.EmployeeName);
    pstmt.setString(3, eps.Designation);
    pstmt.executeUpdate();
    pstmt.close();
    catch (SQLException e)
    System.out.println(e.getMessage());
    My question is how do I publish the InsertData proc. I tried :
    CREATE OR REPLACE PROCEDURE insert_data (e EMPLOYEESTRUCT) AS LANGUAGE JAVA
    NAME 'INSERTDATA(EmployeeStruct)';
    but this gives me PLS-00201, identifier EmployeeStruct must be declared.
    COULD SOMEONE HELP ME/ SHOW ME HOW ?
    I wish to call the java stored proc from an external java program.
    rgds
    Jeevan S
    null

    You can't pass Java classes to Java Stored Procedures via the PL/SQL wrapper. You'll have to write your wrapper to take the int as a NUMBER and the two Strings separately as VARCHAR2s, e.g.:
    CREATE OR REPLACE PROCEDURE insert_data
    EmployeeNum IN NUMBER,
    EmployeeName IN VARCHAR2,
    Designation IN VARCHAR2
    AS LANGUAGE JAVA
    NAME 'InsertData.InsertEmployee(int, java.lang.String, java.lang.String)';
    John H.
    null

  • Java Stored Proc, passing BLOB, not stored in a table.

    I have checked this article, and found it will not suit my needs.
    http://otn.oracle.com/sample_code/tech/java/codesnippet/jdbc/lob/LobToSP.html
    I have even looked at the 4 articles on the "JSP How-To Documents" page.
    I need to pass in a BLOB to my Java Stored proc, but not store it in the DB - My java code manipulates the LOB and it should never go into the DB. I know I could do the normal store, get an id and pass to my JSP... but that is a poor way to implement this. Are there any code samples on how to do this please ?
    D

    WOW! That seems like a very bad design.
    Is it just the compiler that has the problem or is the PL/SQL code inside the stored procedure also affected? For example, if I'm doing an
    EXECUTE IMMEDIATE 'insert ... INTO OtherSchema.tblTest';
    Is this going to be a problem?
    The problem with granting the access explicitly is the Archive Schema, which has the stored procedure that is failing, might not exist at the time when the other schemas are created. Therefore, there is no user to grant permissions to. I solved this by granting permissions to the role and when the archive user is created it is assigned that role.
    This seems like the proper way to solve this problem.

  • XML Parsing in Java Stored Proc--Oracle XML Support Installation?

    I am working with a third party product that is having difficulty running a java stored proc that is parsing a supplied XML file. The proc basically looks like:
    import java.io.IOException;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.FactoryConfigurationError;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.Document;
    import org.xml.sax.SAXException;
    InputStream is = getXMLAsInputStream(xml);
    try {
    DocumentBuilderFactory factory =
    DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse( is );
    ... parse the document ....
    catch (FactoryConfigurationError e) {
    // unable to get a document builder factory
    We are running on 9.2.0.6, HP-UX 64-bit. At first, when we would attempt to run the proc, a database hang would occur; now after attempting to install using loadjava jars for xerces2.6: ORA-29532: Java call terminated by uncaught Java exception:
    javax.xml.parsers.FactoryConfigurationError: Provider
    org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not found)
    The vendor says that the errors we are getting when running are not due to any dependency on xerces or jre1.4, and that we need to "install Oracle XML support", but I'm not certain what this means (I cannot find any documentation on what to install). I believe that there are jars that need to be loaded into the database to support the XML parsing, as jre1.3 does not include built-in XML support, and Oracle 9.2.0.6 uses jre1.3.
    So...does anyone have any thoughts as to how to resolve the missing references? Is there a way to "install Oracle XML support", or is it to install the necessary jars?
    Thanks,
    Candi

    Candi,
    The following resources should be of help:
    Oracle9i Database Release 2 (9.2) Documentation Library
    In particular, check out the following:
    Java Developer's Guide
    Java Stored Procedures Developer's Guide
    XML API Reference - XDK and Oracle XML DB
    XML Database Developer's Guide - Oracle XML DB
    XML Developer's Kits Guide - XDK
    If that doesn't help, then try the following:
    OracleJVM and Java Stored Procedures
    XML Technology Center
    Good Luck,
    Avi.

  • Java stored proc deploy problem

    I get follow error,when I deploy Java stored proc with JDeveloper3.2.
    Errors:
    *** Errors occurred while loading the archive into 8i JVM ***
    How can i do?
    Thanks a lot!!

    The problem is with the OUT parameters. If you read the documentation you will see that OUT parameters
    need to be declared as one element arrays. Hence this should compile:
    CREATE OR REPLACE PROCEDURE TEST ( id IN NUMBER,
    i IN NUMBER,
    j IN VARCHAR2,
    ret1 OUT NUMBER,
    ret2 OUT VARCHAR2,
    k IN NUMBER) AS
    LANGUAGE JAVA NAME 'com.fn.oracle.proc.trading.TestProcedure.testIt(int, double, java.lang.String, int[], java.lang.String[], int)';Cheers, APC

  • Can we call a Java Stored Proc from a PL/SQL stored Proc?

    Hello!
    Do you know how to call a Java Stored Proc from a PL/SQL stored Proc? is it possible? Could you give me an exemple?
    If yes, in that java stored proc, can we do a call to an EJB running in a remote iAS ?
    Thank you!

    For the java stored proc called from pl/sql, the example above that uses dynamic sql should word :
    CREATE OR REPLACE PACKAGE MyPackage AS
    TYPE Ref_Cursor_t IS REF CURSOR;
    FUNCTION get_good_ids RETURN VARCHAR2 ;
    FUNCTION get_plsql_table_A RETURN Ref_Cursor_t;
    END MyPackage;
    CREATE OR REPLACE PACKAGE BODY MyPackage AS
    FUNCTION get_good_ids RETURN VARCHAR2
    AS LANGUAGE JAVA
    NAME 'MyServer.getGoodIds() return java.lang.String';
    FUNCTION get_plsql_table_A RETURN Ref_Cursor_t
    IS table_cursor Ref_Cursor_t;
    good_ids VARCHAR2(100);
    BEGIN
    good_ids := get_good_ids();
    OPEN table_cursor FOR 'SELECT id, name FROM TableA WHERE id IN ( ' &#0124; &#0124; good_ids &#0124; &#0124; ')';
    RETURN table_cursor;
    END;
    END MyPackage;
    public class MyServer{
    public static String getGoodIds() throws SQLException {
    return "1, 3, 6 ";
    null

  • Creating a java stored proc in jdev

    Does anyone have a quick ref guide to creating a java stored proc in jdev? I am missing early steps to correctly setup the project.
    Thanks in advance.

    Assuming you are using ADF BC, you can try something like the following on your Application Module:
    /* our java method to call a stored procedure to send email */
    public void sendEmail(String fromEmailAddress, String toEmailAddress,
    String subject, String body1, String body2,
    String body3, String body4, String body5) {
    Object[] parms =
    { fromEmailAddress, toEmailAddress, subject, body1, body2, body3,
    body4, body5 };
    callStoredProcedure("MSKCC.proc_send_mail(?,?,?,?,?,?,?,?)", parms);
    protected void callStoredProcedure(String stmt, Object[] bindVars) {
    PreparedStatement st = null;
    try {
    // 1. Create a JDBC PreparedStatement for
    st =
    getDBTransaction().createPreparedStatement("begin " + stmt + ";end;", 0);
    if (bindVars != null) {
    // 2. Loop over values for the bind variables passed in, if any
    for (int z = 0; z < bindVars.length; z++) {
    // 3. Set the value of each bind variable in the statement
    st.setObject(z + 1, bindVars[z]);
    // 4. Execute the statement
    st.executeUpdate();
    } catch (SQLException e) {
    throw new JboException(e);
    } finally {
    if (st != null) {
    try {
    // 5. Close the statement
    st.close();
    } catch (SQLException e) {
    }

  • Using an existing connection in a Java Stored Proc

    Hi,
    I have to invoke a Java stored procedure from a PL/SQL stored proc. In the Java stored proc I open a database connection & execute some SQLs. To do this can I use the same connection that is used to invoke the PL/SQL stored proc. In other words can we use the existing PL/SQL connection within a Java stored proc that is being called by the former PL/SQL instead of creating a new connection?
    Thanks in advance.
    Sunitha

    Ok I understood how to get the default connection from http://www.oracle.com/technology/tech/java/sqlj_jdbc/htdocs/jdbc_faq.htm#05_01
    Connection conn = DriverManager.getConnection("jdbc:default:connection");However, I find that the Java stored proc is running slower in Oracle VM than invoking it from a command line Java program using thick driver from a remote machine.
    Thanks anyway.
    Sunitha.

  • Problem with java stored procs.

    Is there a restriction on accessing XML documents from Java stored procs?
    I have a Java program to parse XML document and return a string. If I run this program as a stand alone, the program runs fine.
    I loaded the oracle xmlparser.jar into ORACLE8i db sucessfully (used -resolve option). Then I loaded my .class file with -verbose and -resolve option and I did not get any erros. I created function which return string. When I ran the function, I did not get any value bacmk.
    Can I use System.out.println in java programs in ORACLE8i. If I can where can I see the output when the program runs? I not waht other mehtods I can use to debug the program running in ORACLE8i JVM.
    Thank You

    Hello again,
    I read the documentation of 9i and found some hints about different TCP/IP socket handling of 9i and a standard JVM.
    There are some parts that give hints but I couldn't find a sample code to show how to handle the differences.
    Could anyone tell me how to handle the differences or give some links to sample code?
    Thanks
    Detlev

  • ORA-03113 error when running the Java stored proc demos

    Hi there,
    Has anyone else run into this issue. When attempting to transfer an object type from Java to Oracle - through a Java stored proc - the session crashes with:
    ORA-03113: end-of-file on communication channelLooking in the trace file generated the error message looks something like:
    ksedmp: internal or fatal error
    ORA-07445: exception encountered: core dump [0x8fe04468] [SIGTRAP] [unknown code] [0x8FE59034] [] []
    Current SQL statement for this session:
    select pointruntime.jdistance(point(1, 2), point(2, 3)) from dual
    ----- Call Stack Trace -----
    calling              call     entry                argument values in hex     
    location             type     point                (? means dubious value)    
    ksedmp+764           call     ksedst               0 ? 2C4F4A ? 2C ? 98968000 ?
                                                       DB02C ? 27A50000 ?
    ssexhd+956           call     ksedmp               3 ? 0 ? 8FE5E790 ? 5905870 ?
                                                       8FE0434C ? 40895E4 ?
    0x9012c860           call     ssexhd               5 ? BFFEEF70 ? BFFEEFB0 ? 0 ?
                                                       0 ? 0 ?As you can see from the trace snippet above, I was attempting to run one of the Oracle Java stored procedure demos. Has anyone successfully run those demos? Specifically the ones where complex types (table objects or the Point object) are passed back to Oracle from the JVM.
    I would appreciate some help with this. The code works fine in a Windows or Solaris environment but barfs on Apple. Truly annoying....
    Anyone?
    Thanks in advance,
    Alex

    Yes,
    Apologies for not stating that information, Steve. Was a bit naughty of me! I guess the reason I didn't was because I just wanted to hear if anyone else running Oracle on Mac received such errors when executing the Java stored proc demos (specifically, the execution of PointRuntime.jDistance). Nevertheless, here's the relevant info from the trace file:
    Dump file /Users/oracle/admin/sandbox/udump/sandbox_ora_1861.trc
    Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - Production
    With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
    ORACLE_HOME = /Users/oracle/product/10.1.0/db
    System name:     Darwin
    Node name:     maczilla.local
    Release:     8.3.0
    Version:     Darwin Kernel Version 8.3.0: Mon Oct  3 20:04:04 PDT 2005; root:xnu-792.6.22.obj~2/RELEASE_PPC
    Machine:     Power Macintosh
    Instance name: sandbox
    Redo thread mounted by this instance: 1
    Oracle process number: 10
    Unix process pid: 1861, image: [email protected] for the Java version, according to the readme file in the javavm directory, I am running 1.4.1:
    1.5  Java Compatibility
    This release has been thoroughly tested with Sun's Java Compatibility
    Kit for the JDK 1.4.1. Oracle is committed to OracleJVM keeping pace
    with Java and other Internet standards.

  • Parse XML in a java stored proc

    I am trying to parse an xml document in a java stored procedure. Just following my nose, I have developed a stored proc that works fine in development (outside the database using JRE 1.4.1) using the Xerces 2.5 parser. But, after having transferred the xerces xercesImpl.jar, xmlapis.jar, and my implementation class into oracle using loadjava when I call my stored proc the code throws an exception trying to build the document with an error like:
    NoClassDef exception org.apache.xerces.jaxp.DocumentFactoryBuilderImpl
    My Code looks like this:
    import java.io.IOException;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.FactoryConfigurationError;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.Document;
    import org.xml.sax.SAXException;
    InputStream is = getXMLAsInputStream(xml);
    try {
    DocumentBuilderFactory factory =
    DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse( is );
    ... parse the document ....
    catch (FactoryConfigurationError e) {
    // unable to get a document builder factory
    The exception caught is a FactoryConfigurtionError.
    I'm not particularly attached to xerces, I'm really just looking for a way to parse XML inside my java stored proc, so any help to solve my problem, or an alternative suggestion will be greatly appreciated.
    thanks
    Dale

    I looked again and sure enough the xerces implementation classes were missing. I had run a .cmd file containing these two lines, but it looks like only the first one ran...
    loadjava -u ncc/xyz@usd -v -r M:\Database\JavaGeocode\Xerces2_5_0\xml-apis.jar
    loadjava -u ncc/xyz@usd -v -r M:\Database\JavaGeocode\Xerces2_5_0\xercesImpl.jar
    Now I've got everything working fine with Xerces!
    Dale

  • Java Stored Proc and Oracle 8.0.6.20?

    Hi,
    I have a customer using Oracle 8.0.6 (on multi-platforms). We'll need to implement a pl/sql which needs to execute an external script.
    My understanding is there are only 2 ways to achieve this: (a) use Java stored procedure, (b) use C/C++ library
    Question 1: Is Java Stored Proc available in 8.0.6?
    Question 2: Is there anywhere I can download Oracle 8.0.6 (Windows, or Tru64, Linux)?
    - Will

    java in the database was introduced from Oracle8i onwards. this version of Oracle does not support java virtual machine in the database.
    You would need to use C/C++ external procedures.

  • Java stored proc status

    hello.
    What would trigger the change of "STATUS" from valid to invalid
    for a java stored procedure (status of the PROCEDURE, not the
    java class/source)?
    E.g.
    - loaded a java source/class
    - published it with CREATE PROCEDURE ...
    - the procedure inserts a row into some table X
    - select* from user_objects where object_type = 'PROCEDURE'; shows that
    the proc is valid
    - call the proc, fine
    - delete a column from the table X
    - select* from user_objects where object_type = 'PROCEDURE'; shows that
    the proc is still VALID
    - call the proc, the call actually completed without error! (but the new row didn't get inserted into the table)
    When the schema of a table that a java stored proc refers
    to changes, will the java stored proc automatically marked
    as "INVALID"? If not, when will this status changed from
    VALID to INVALID?
    Thanks.
    Min

    Min:
    A java stored procedure is marked as VALID or INVALID depending on whether Oracle had any problems loading the class file into the database. Since you had no problems loading the class file it will always be valid.
    Now, after you deleted the column in the table I would assume that the java stored procedure would have a problem when it tried to do an insert and it would throw an exception. Your java stored procedure is VALID, it just isn't executing properly and is more than likely throwing an exception.
    Sometimes an exception thrown from a jsp is written to a log file instead of to the console. I suspect that this is the case in your situation. You think that the call to the jsp executed with no errors, but I bet it didn't. You will probably find the errors somewhere in the oracle\ora90\admin\mydatabase directory. Look at the latest .trc file. (Note: the path I gave to the .trc files may be different depending on what version of oracle you are using).

Maybe you are looking for

  • Report to check Po o/p processing status & details

    Dear experts , Is there a standard SAP report that give me the details of a PO o/p type processing status with details ? Regards Anis

  • Do the photos stay in aperture?

    Hello, a dumb question probably. I imported some photos into aperture on my imac and am delighted to see they have appeared on my macbook. A couple of questions. Can I choose some older photos from my library to do this? Are the ones that have downlo

  • Entity details is shown Type mismatch: 'FormatDateTime'

    Hi, all: The entity details of a data grid in HFM 11G is shown the following VBScript runtime error: Microsoft VBScript runtime ??800a000d' Type mismatch: 'FormatDateTime' */hfm/Data/EntityDetails.asp, ?C266* The date format is always mm/dd/yyyy in H

  • LMS4.2.2 incomplete pre configured logrotation

    Following growing logs exists, but not preconfigured in LMSs log rotation: ConfigMgmtServer.log ani.log ICServer.log CAAMServer.log UDM.log rme_ctm.log could be getting large after weeks

  • LINKSYS WRT54G

    I have a Linksys WRT 54G router that is giving me connectivity problems. I have two laptops, one running Vista, the other running XP and neither are able to connect wirelessley to my router. I can see and connect to other users' routers in my area wi