Why returning string from java stored function failed ?

I created java stored function: it's doing http post, parsing xml from http reply, and returning string result.
Sometimes, it doesn't return any value. What can be a reason ?
The high level procedure, has following form:
class SBE {
public static String call(String arg0) {
SBE sbe=new SBE("d:\\oracle\\ora81\\network\\log\\SBE.log");
String result=SBEParser.go(sbe.sendRequest(arg0, ""), sbe.logger);
sbe.logger.log(result);
sbe.logger.log("Finish SBE intetraction");
return result;
PLSQL wrapper has a simple form:
create or replace package PG_SBE as
function CALL(arg0 in varchar2) return varchar2;
end;
create or replace package body PG_SBE as
function CALL(arg0 varchar2) return varchar2 as language java name 'SBE.call(java.lang.String) return java.lang.String';
end;
In log file ("d:\\oracle\\ora81\\network\\log\\SBE.log"), I can find message :
"Finish SBE intetraction"
but query:
select pg_sbe.call("any argument") from dual;
doesn't finish.
What can be a reason ? What can I do to trace stage of convertion java string to varchar ?
Please help me...
Marek

This comes up periodically. It just isn't possible using that type of approach. Probably the best you could do is the create an ADT (containing collections) and use that to pass a 'batch' of information.
Hopefully this will get addressed in the next release of the database.

Similar Messages

  • Why returning string from java stored function failed ?  HELP ME, PLEASE

    Hi everybody,
    I created java stored function: it's doing http post, parsing xml from http reply, and returning string result.
    Sometimes, it doesn't return any value. What can be a reason ?
    The high level procedure, has following form:
    class SBE {
    public static String call(String arg0) {
    SBE sbe=new SBE("d:\\oracle\\ora81\\network\\log\\SBE.log");
    String result=SBEParser.go(sbe.sendRequest(arg0, ""), sbe.logger);
    sbe.logger.log(result);
    sbe.logger.log("Finish SBE intetraction");
    return result;
    PLSQL wrapper has a simple form:
    create or replace package PG_SBE as
    function CALL(arg0 in varchar2) return varchar2;
    end;
    create or replace package body PG_SBE as
    function CALL(arg0 varchar2) return varchar2 as language java name 'SBE.call(java.lang.String) return java.lang.String';
    end;
    In log file ("d:\\oracle\\ora81\\network\\log\\SBE.log"), I can find message :
    "Finish SBE intetraction"
    but query:
    select pg_sbe.call("any argument") from dual;
    doesn't finish.
    What can be a reason ? What can I do to trace stage of convertion java string to varchar ?
    Please help me...
    Best regards
    Marek

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Stefan Fdgersten ([email protected]):
    Maybe your call is wrong... Shouldn't there be a "?" instead of "1"?
    Your code:
    String myquery = "begin :1 := jspTest; end;";
    I provide my (working) call from java as an example. Maybe it is of any help... :)
    import java.sql.*;
    import oracle.jdbc.driver.*;
    public Vector getAllHosts() throws SQLException {
    //return getHosts(false, -1);
    Connection conn = null;
    CallableStatement cs = null;
    Vector hostV = new Vector();
    try {
    conn = getConnection();
    String query = "{ ? = call curTestPkg.curTestFunc}";
    cs = conn.prepareCall(query);
    cs.registerOutParameter(1, OracleTypes.CURSOR);
    cs.execute();
    ResultSet rs = ((OracleCallableStatement)cs).getCursor(1);
    while (rs.next()) {
    Host host = new Host(
    rs.getInt("hostid")
    , rs.getString("name")
    , rs.getString("descr")
    , rs.getString("os"));
    hostV.add(host);
    cs.close();
    return hostV;
    } finally {
    close(conn, cs);
    <HR></BLOCKQUOTE>
    hi Stefan thanx.....even after changing the call statement i get the same error. i changed query string as...
    String myquery = "{ ? = call jspTest}";
    CallableStatement cst = con.prepareCall(myquery);
    Can u please check out my call sepc that i have written in pl/sql and plz let me know it there is any error in that.
    PS : THIS IS THE FIRST TIME I AM WORKING WITH PL/SQL AND IT IS URGENT

  • Return 2 values (string, number) multiple rows, from java stored function

    I would like to return 2 values (String, number prefered but String, String will work) from a java stored function.
    I was able to successfully return a varray of varchar2 values but I was wondering if it is possible to return 2 values by using a varray?
    Is it even possible? I tried using combinations of types which included a varray of objects (with 2 attributes) or a type as table of objects but I couldn't figure out how in my java code to set these values. Also what would my java function return type be and what Oracle type would map to it?
    Any help and examples or pointers would be great.
    Thanks,
    Dennis

    Thanks to all. I finally figured it out through all the pieces on the web.
    Here is what worked for me. First create 2 oracle types. One object type to represent the "columns" I will pass back:
    CREATE OR REPLACE TYPE COST_OBJ AS OBJECT (COST_NAME NVARCHAR2(50), COST_VALUE number ) NOT FINAL
    note: make sure the "strings" are defined as NVARCHAR2 or Java will puke if it is just VARCHAR2.
    Then create a table type to hold your objects defined as following:
    CREATE OR REPLACE TYPE COST_OBJ_TABLE is table OF COST_OBJ
    Then create the oracle stored function that is a wrapper to the java function:
    CREATE OR REPLACE FUNCTION get_Costs(Name VARCHAR2, evalDate VARCHAR2, fuelCodeID NUMBER) return COST_OBJ_TABLE
    is language java name
    'com.costs.storedProcedures.Cost.getCosts(java.lang.String, java.lang.String, int) return oracle.sql.ARRAY'
    Once that is done, Oracle is ready. The Java function looks something like this:
    public ARRAY getCosts(String name, String evalDate, int fuelCodeID) {
    DBAccess da = getDBAccess();
    // get a handle on the connection
    Connection conn = da.getConnection();           
    // The stuff that will be returned should be as type object array
    // make it to the size of the number of fuelcomponents passed in
    Object[] returnStuff = new Object[3];
    // create the type of struct that is defined on the database
    StructDescriptor structDesc =
    StructDescriptor.createDescriptor("CY_UMAP.COST_OBJ", conn);
    for (int i = 0; i < returnStuff .size(); i++) {
    Object[] costValues = new Object[]{
         "This is object " + i,
         new Integer ( i ) };
    STRUCT cost_obj = new STRUCT(structDesc, conn, costValues);
    returnStuff[i] = cost_obj;
    ArrayDescriptor x_ad = ArrayDescriptor.createDescriptor (
    "CY_UMAP.COST_OBJ_TABLE", conn);
    ARRAY x_array = new ARRAY(x_ad, conn, returnStuff);
    return x_array;
    I hope this helps others.
    Dennis

  • Return national language strings from java stored procedures

    Hi, all.
    How does i can return String which contains national characters from java stored procedure? I.e. convert UTF java string to national language of database. It's does not processing automatically (why?).
    declaration of procedure:
    CREATE OR REPLACE FUNCTION TestNLSString RETURN VARCHAR2
    AS
    LANGUAGE JAVA
    NAME 'test.SomeClass.getNLSString() return java.lang.String';
    SELECT TestNLSString AS X FROM DUAL;
    X
    iiiii
    OS: Windows 2000 Server
    Oracle Server version: Oracle 8.1.7.1.4

    Ok. I had a specific problem.
    I want to use java stored procedure (function) to make a connection to remote db using supplied connection parameters make some quieries there end return results in a form of structured data - object.
    I have defined an object type in a database where the function will reside. I granted execute privilege to public user on this type, made public synonyms to both, the object type and the function, so anybody connected to the same database would have an access to this functionality.
    I supposed that if I supply connection parameters for some other user but the same database when running the function, everything should go smooth. Yeah.
    My java code executed ok: it made a connection to the db with some x user, it resolved object type descriptor given (oracle.sql.StructDescriptor), but pl/sql wrapper function reported the error I've mentioned. If I executed the function giving it the connection parameters for same account as where object type was declared, everything went fine.
    My final solution is:
    Make TWO! connection in java code: 1st for ("jdbc:default:connection:"), 2nd for remote database account.
    Use first connection to construct oracle.sql.StructDescriptor
    Use second connection to retreive data from remote db

  • How to return custJava Object from Java Stored Function/Procedure to Java Application

    I WILL PAY $100 FOR SOLUTION.
    Oracle JDBC documentation gives step by step on how to return Oracle Type Object to Java Application. No question here.
    But is it possible to create Java Stored Function [getMyClass() ] which returns CUSTOM Java based object [MyClass] to Java application like:
    //java stored function
    class Foo
    public static MyClass getMyClass()
    return new MyClass();
    //java class I want to return to Java
    class MyClass
    public String getGreetings(String name)
    return "Hello " + name;
    I tried to do it using intermittent Oracle
    Type Object and OracleConnection map to make binding between Java->Oracle->Java. I could
    not get throgh meaningless run time ORA Errors. Any kind of help would be greatly
    appreciated. If you know the answer please
    post it or e-mail [email protected]
    null

    You don't say which version of the database you are on. There's an interesting looking article on OTN on handling CLOBs in JDBC in 10g. It may well be useful for earlier versions too (but no guarantees).
    Cheers, APC

  • Recursing through table / complex return types in Java Stored Functions

    I have a table representing a tree with arbitrary depth, of the form:
    ID NUMBER(10) PRIMARY KEY,
    NAME VARCHAR2(20),
    PARENT NUMBER(10)
    with PARENT being a foreign key for ID, so that top-level nodes in the tree have a NULL PARENT, and other nodes have the ID of their parent node in the PARENT field.
    I want a good way to get a row representing a node as well as all its ancestor nodes recursively up to the top level. I do this a lot in my Java application, and right now it works by just getting each row, checking if PARENT is null, and recursing again until I get the top-level node. Since this recursion is in Java and I do multiple queries it's rather slow, and I'd rather perform this operation in the database (using a Java Stored Function/Procedure or PL/SQL).
    I'm no good at PL/SQL so don't have a clue how to go about doing this sort of thing, and although I can write a Java Stored Function that does the same recursion I do in the application, I don't know how to return the results. I can't return a REF CURSOR type since the results are from multiple queries, and I can't find any documentation about how to return structured types from a JSF.
    If anyone could give me a near-complete PL/SQL listing that does this or (better) help me to complete my Java Stored Function by returning the results in a structured type.

    You are my own personal God (for the day). Thanks, exactly what I needed, and all in one query with no procedural.

  • Returning strings from Java- C JNI calls

    <newbie to JNI>
    I have an application written in Java that accesses a .DLL written in C. The .DLL does low-level communication to a hardware device. I've got it all working except for one little problem:
    For all of the functions I need to return an integer return code and for some of them I also need to return a string, such as a serial number, version string, or whatever.
    Try as I might, I can't find any information on how to return two values from a function call (pretty sure I can't in Java).
    SO, I tried to find out how to stuff the version string into a string object variable in the class object the DLL API is defined in. I can't figure out how to do that either...
    e.g. the following Java code:
    class LLDev {
    /* --- Load the .DLL -------------------- */
    static { System.loadLibrary("LLDev"); }
    /* --- Error Codes ---------------------- */
    public static final int LLDOk = 0;
    public static final int LLDInitErr     = -1;
    /* --- Public Variables ----------------- */
    public static String DLLVersion;
    /* --- Public Methods ------------------- */
    public native int InitLLDev();
    When I invoke LLDev.InitLLDev() from Java I want the C .DLL function Java_LLDev_InitLLDev to put the DLL Version string in the LLDev object's DLLVersion field and return an error code as the function result.
    Is this possible???? Is this the right way to do this?? I tried to define the API with methods that return strings instead of integer return codes but the customer using the class wants all of the methods to return a return code in case of some error (e.g. reading the serial number from the device could fail...)

    1. In general, the java way to deal with errors is by throwing exceptions, not using return codes. But OK, you are stuck with the user requirement.
    2. I suggest you have the native method take as an argument a java object which will accept a string as input. In other words, it has a string "setter".
    3. So in your native method, if the function succeeds, it writes your string result to that object, and you can futrther process it when the native method returns a "success" code.
    4. There are JNI methods for
    o looking up the class of a java object.
    o looking up the method of a java class.
    o invoking the method.

  • Returning objects from Java stored procedures

    I need to pass an object from Java to a Java SP which updates the object and returns the object back. The Java SP will be calling a PL/SQL procedure which returns some nested tables that I want to stick into the passed object.
    I tried using "IN OUT" for the object in the call spec but got an error that it was not "appropriate for the parameter". So, the next option seems to be to pass it in and then return it from the Java SP. I'm just wondering though what the the best approach for accomplishing this? I've looked through some of the sample code on the OTN but haven't found anything yet that really helps.

    I am trying to use custom object classes. I have setup a type map for the connection and my custom class implements SQLData. Yet, when my client tries to call the Java SP, it gets ORA-00932 complaining of inconsistent data types (expected IN conversion failed).
    I turned on some debug info (i.e. oracle.jdbc.sql=true) but it didn't provide any useful info in regards to why I'm getting this error. Unfortunately, the JDBC Developer's Guide does not provide full examples of the code.

  • Calling a WebServices From Java Stored Proc fails with Connection refused

    I have followed the example in Note:220662.1 on Metalink step by step.
    I am using two windows machines (2000 SP4). I have Oracle 9.2.0.5 EE on one of them and OC4J 9.0.4 standalone on the other(running on JVM 1.4.2_05-b04). The 2 servers "see" each other over the network.
    I can execute the stub from the database machine:
    C:\WebServices\HelloWorld>java HelloWorldImplWSStub
    Hello World - The current time is Sat Aug 21 11:56:20 EDT 2004When running it from the database, I get:
    SQL> select ws_hello_world from dual;
    select ws_hello_world from dual
    ERROR at line 1:
    ORA-29532: Java call terminated by uncaught Java exception: [SOAPException:
    faultCode=SOAP-ENV:IOException; msg=Connection refused;
    targetException=java.net.ConnectException: Connection refused]
    Elapsed: 00:00:21.02The trace file generated on the database server machine looks like:
    [SOAPException: faultCode=SOAP-ENV:IOException; msg=Connection refused; targetException=java.net.ConnectException: Connection refused]
      at oracle.soap.transport.http.OracleSOAPHTTPConnection.send(OracleSOAPHTTPConnection.java:765)
      at org.apache.soap.rpc.Call.invoke(Call.java:261)
      at HelloWorldImplWSStub.sayHelloWorld(HelloWorldImplWSStub.java:52)Here is the stub code generated using JDeveloper 9.0.5.1:
    import oracle.soap.transport.http.OracleSOAPHTTPConnection;
    import org.apache.soap.encoding.SOAPMappingRegistry;
    import java.net.URL;
    import org.apache.soap.rpc.Call;
    import org.apache.soap.Constants;
    import java.util.Vector;
    import org.apache.soap.rpc.Response;
    import org.apache.soap.rpc.Parameter;
    import org.apache.soap.Fault;
    import org.apache.soap.SOAPException;
    import java.util.Properties;
    public class HelloWorldImplWSStub  {
      public HelloWorldImplWSStub() {
        m_httpConnection = new OracleSOAPHTTPConnection();
        m_smr = new SOAPMappingRegistry();
      public static String endpoint = "http://oc4jsrv:8888/MyWorkarea-OC4J-context-root/HelloWorldImplWS";
      public String getEndpoint() {
        return _endpoint;
      public void setEndpoint(String endpoint) {
        _endpoint = endpoint;
      private static OracleSOAPHTTPConnection m_httpConnection = null;
      private static SOAPMappingRegistry m_smr = null;
      public static String sayHelloWorld() throws Exception {
        String returnVal = null;
        URL endpointURL = new URL(_endpoint);
        Call call = new Call();
        call.setSOAPTransport(m_httpConnection);
        call.setTargetObjectURI("HelloWorldImplWS");
        call.setMethodName("sayHelloWorld");
        call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
        Vector params = new Vector();
        call.setParams(params);
        call.setSOAPMappingRegistry(m_smr);
        Response response = call.invoke(endpointURL, "");
        if (!response.generatedFault()) {
          Parameter result = response.getReturnValue();
          returnVal = (String)result.getValue();
        else {
          Fault fault = response.getFault();
          throw new SOAPException(fault.getFaultCode(), fault.getFaultString());
        return returnVal;
      public void setMaintainSession(boolean maintainSession) {
        m_httpConnection.setMaintainSession(maintainSession);
      public boolean getMaintainSession() {
        return m_httpConnection.getMaintainSession();
      public void setTransportProperties(Properties props) {
        m_httpConnection.setProperties(props);
      public Properties getTransportProperties() {
        return m_httpConnection.getProperties();
       public static void main(String[] argv) throws Exception   {    
        HelloWorldImplWSStub hstub = new HelloWorldImplWSStub();    
        System.out.println(hstub.sayHelloWorld());  
    }The PL/SQL function code:
    CREATE OR REPLACE FUNCTION ws_hello_world RETURN VARCHAR2
    AS LANGUAGE JAVA
    NAME 'HelloWorldImplWSStub.sayHelloWorld() return java.lang.String';Any help would be greatly appreciated.

    Hello,I have the same problem. Did you find any solution to it?
    Thanks. Diego (Argentina)

  • Return String from Oracle stored proc using Excel 2003 VBA

    Hi to everyone,
    I've got a problem that remains unsolved for many days. I am trying to return a value of an oracle stored procedure using Excel VBA. It might seem trivial, however it's not for someone, who has never done it before...
    OS: Win XP SP3
    Excel 2003
    Ora Client: 11g
    By trying different things I have noticed, that I could have troubles with the ODBC-connection. Maybe I am not using the right one. To store data returned from select statements I have an ODBC-Connection (Driver: Oracle in XE), which works perfectly, e.g.:
    Sub Extract_Data()
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim db_name, UserName, Password As String
    cn.Open db_name, USerName, Password
    sql_statement = "SELECT some_text FROM some_table"
    Set rs = cn.Execute(sql_statement)
    rs.MoveFirst 'jump to the first entry in the data list
    Row = 2
    While Not rs.EOF
    'save the data to a worksheet
    ip.Cells(Row, 2) = rs(0).Value
    Row = Row + 1
    rs.MoveNext
    Wend
    End Sub
    Now I need to execute a stored procedure to return a semi-colon delimited string.
    I have tried the following:
    Public Sub obj_class()
    Dim cn As New ADODB.Connection
    Dim strSQL, cn As String
    Dim adoCMD As ADODB.Command
    Dim adoRS As ADODB.Recordset
    Set wb = Excel.ActiveWorkbook
    Set ih = wb.Sheets("InfoSheet")
    cn.Open db_name, UserName, Password
    Set adoCMD = New ADODB.Command
    With adoCMD
    .ActiveConnection = cn
    .CommandText = "S#mdb$stg_da_extr_util.get_all_classes_of_classif"
    .CommandType = adCmdStoredProc
    .Parameters.Refresh
    '------ and here comes the error saying:
    '------ could not find the object in the collection corresponding to the name or ordinal reference requested by the application
    .Parameters("i_caller").Value = "'STG_DATA_REQUEST'"
    .Parameters("i_obj_classif_id").Value = 120
    Set adoRS = .Execute()
    End With
    End Sub
    I did asked on the forum:
    http://www.access-programmers.co.uk/forums/showthread.php?p=1241667#post1241667
    but unfortunately without success.
    Could it be, that my ODBC-connection is wrong? When debugging the connection string, I find the Provider=MSDASQL5.1.
    I have moderate knowledge in VBA, but absolutely a newbie with Oracle DB. Is there any source of information that can help solving this issue? Looking forward to hearing from you, as I am almost giving up... ;(

    My VBA is super rusty. Does that error come after Parameters.Refresh, or after .Parameters("i_caller").Value = "'STG_DATA_REQUEST'"?
    If it's the second one, you'll need the definition of the stored procedure so you can see what parameters it's expecting. That'd mean you're getting something wrong with the names.

  • Executing batch file from Java stored procedure hang

    Dears,
    I'm using the following code to execute batch file from Java Stored procedure, which is working fine from Java IDE JDeveloper 10.1.3.4.
    public static String runFile(String drive)
    String result = "";
    String content = "echo off\n" + "vol " + drive + ": | find /i \"Serial Number is\"";
    try {
    File directory = new File(drive + ":");
    File file = File.createTempFile("bb1", ".bat", directory);
    file.deleteOnExit();
    FileWriter fw = new java.io.FileWriter(file);
    fw.write(content);
    fw.close();
    // The next line is the command causing the problem
    Process p = Runtime.getRuntime().exec("cmd.exe /c " + file.getPath());
    BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    while ((line = input.readLine()) != null)
    result += line;
    input.close();
    file.delete();
    result = result.substring( result.lastIndexOf( ' ' )).trim();
    } catch (Exception e) {
    e.printStackTrace();
    result = e.getClass().getName() + " : " + e.getMessage();
    return result;
    The above code is used in getting the volume of a drive on windows, something like "80EC-C230"
    I gave the SYSTEM schema the required privilege to execute the code.
    EXEC DBMS_JAVA.grant_permission('SYSTEM', 'java.io.FilePermission', '&lt;&lt;ALL FILES&gt;&gt;', 'read ,write, execute, delete');
    EXEC DBMS_JAVA.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
    EXEC DBMS_JAVA.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
    GRANT JAVAUSERPRIV TO SYSTEM;
    I have used the following to load the class in Oracle 9ir2 DB:
    loadjava -u [system/******@orcl|mailto:system/******@orcl] -v -resolve C:\Server\src\net\dev\Util.java
    CREATE FUNCTION A1(drive IN VARCHAR2) RETURN VARCHAR2 AS LANGUAGE JAVA NAME 'net.dev.Util.a1(java.lang.String) return java.lang.String';
    variable serial1 varchar2(1000);
    call A1( 'C' ) into :serial1;
    The problem that it hangs when I execute the call to the function (I have indicated the line causing the problem in a comment in the code).
    I have seen similar problems on other forums, but no solution posted
    [http://oracle.ittoolbox.com/groups/technical-functional/oracle-jdeveloper-l/run-an-exe-file-using-oracle-database-trigger-1567662]
    I have posted this in JDeveloper forum ([t-853821]) but suggested to post for forum in DB.
    Can anyne help?

    Dear Peter,
    You are totally right, I got this as mistake copy paste. I'm just having a Java utility for running external files outside Oracle DB, this is the method runFile()
    I'm passing it the content of script and names of file to be created on the fly and executed then deleted, sorry for the mistake in creating caller function.
    The main point, how I claim that the line in code where creating external process is the problem. I have tried the code with commenting this line and it was working ok, I made this to make sure of the permission required that I need to give to the schema passing security permission problems.
    The function script is running perfect if I'm executing vbs script outside Oracle using something like "cscript //NoLogo aaa1.vbs", but when I use the command line the call just never returns to me "cmd.exe /c bb1.bat".
    where content of bb1.bat as follows:
    echo off
    vol C: | find /i "Serial Number is"
    The above batch file just get the serial number of hard drive assigned when windows formatted HD.
    Same code runs outside Oracle just fine, but inside Oracle doesn't return if I exectued the following:
    variable serial1 varchar2(1000);
    call A1( 'C' ) into :serial1;
    Never returns
    Thanks for tracing teh issue to that details ;) hope you coul help.

  • ResultSet from Java Stored Procedures

    Hi,
    How do I obtain a resultset from a Java Stored Procedure?
    My stored procedure, deployed in Oracle8i, has Database package as sample.Have published setConnection() and getDept() methods.
    Code for Java Stored Procedure:
    package SPPackage;
    import java.sql.*;
    public class StoredProcApplication {
    protected static Connection connection = null;
    protected static Statement stmt = null;
    protected static ResultSet res = null;
    public static void setConnection() throws SQLException {
    connection = new oracle.jdbc.driver.OracleDriver().defaultConnection();
    public static void getDept(Object[] obj) throws SQLException {
    if (connection == null) {
    setConnection();
    if (stmt == null) {
    stmt = connection.createStatement();
    if (res == null) {
    res = stmt.executeQuery("select * from DEPT");
    obj[0] = res;
    Code for TesterApplication :
    package SPPackage;
    import java.sql.*;
    public class TesterApplication {
    private static final String URL = "jdbc:oracle:thin:@sandeep:1521:oracle8i";
    private static final String userId = "sandeep";
    private static final String password = "sandeep";
    private Connection connection;
    private CallableStatement stmt;
    private ResultSet res;
    public void setConnection() throws ClassNotFoundException,SQLException {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    connection = DriverManager.getConnection(URL,userId,password);
    public void getResultFromSP() throws SQLException {
    //prepare to call the stored procedure
    stmt = connection.prepareCall("{call sample.getDept(?)}");
    //register the OUT parameters
    stmt.registerOutParameter(1,Types.OTHER);
    //execute the query
    stmt.execute();
    ResultSet res = (ResultSet)stmt.getObject(1);
    while (res.next()) {
    System.out.print(res.getInt(1) + " | " );
    System.out.print(res.getString(2) + " | " );
    System.out.print(res.getString(3) + " \n " );
    public TesterApplication() throws SQLException,ClassNotFoundException {
    try {
    setConnection();
    getResultFromSP();
    } finally {
    if (res != null) { res.close(); res = null; }
    if (stmt != null) { stmt.close(); stmt = null; }
    if (connection != null) { connection.close(); connection = null; }
    public static void main(String[] args) {
    try {
    TesterApplication ta = new TesterApplication();
    } catch (Exception e) {
    System.err.println("Error while executing stored procedure " + e.getMessage());
    e.printStackTrace();
    When I run the TesterApplication, I get the following exception :
    java.sql.SQLException: Invalid column type: get_internal_type
    at oracle.jdbc.dbaccess.DBError.check_error(Compiled Code)
    at oracle.jdbc.driver.OracleStatement.get_internal_type(Compiled Code)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(Compiled Code)
    Also, if I want to execute the ResultSet in the stored proc itself, and return the values as Arrays of int[], and String[], how do I do it?By default the you can populate only int[0], String[0] , i.e. only one value!!!
    if my statement is unknown, i.e, it might return a combination of updates and resultsets, how do I go about processing the result?
    Please advise!!
    TIA
    Sandeep
    null

    Hi kkirk,
    I found the post you mentioned.Well it dates back to November 1999 - "Problem returning resultset or ARRAY from java stored proc" by Stuart Popejoy ([email protected]).Too bad, it is still not solved!!
    I am not very good at PL/SQL.However, it would still be helpful, if you could post the code here, or at my email address.
    Meanwhile, I was trying this during the week-end.There seems to be a glimmer of hope!!
    Let me know, if this makes sense :
    CallableStatement cs = connection.prepareCall("begin open ? for select * from dept; end");
    try {
    cs.registerOutParameter(1,OracleTypes.CURSOR);
    ResultSet res = ((OracleCallableStatement)cs).getCursor(1);
    while (res.next()) {
    //get the values
    } catch (Exception e) {
    e.printStacktrace();
    However, I am getting an exception trace
    Error while executing stored procedure Invalid column type: getLong
    java.sql.SQLException: Invalid column type: getLong
    at oracle.jdbc.dbaccess.DBError.check_error(Compiled Code)
    at oracle.jdbc.driver.OracleStatement.getLongValue(Compiled Code)
    Not quite sure why this is happening!!
    TIA,
    Sandeep
    null

  • Passing array from java stored procedure to plsql

    I have a java store procedure that is parsing an xml document and returning element values to my plsql application(8.1.7). I'm mapping a java.lang.String return type to VARCHAR2. However I'm running into the 4k limit when trying to return a string from java that is over 4k. Truncation of varchar returning over 4k is a known issue in 8i.
    So my next idea was to split that value of the element into 2000char and put in an array then pass that back to the plsql procedure. I know that oracle.sql.ARRAY can be converted into a plsql TABLE. But I believe you can only use the oracle.sql.ARRAY type when you are doing jdbc programming and are working with a connection.
    SO FINALLY MY QUESTION IS...
    Can anyone think of a solution that will allow me to pass over 4k of character data from my java stored procedure (not jdbc), back to my plsql app?
    Thanks.

    My understanding is that oracle 8 has a 4k limitation on any plsql function return data. A varchar can hold 32k within a function/package, but it cannot return more than 4k outside it's scope.
    Do you have an example you could share where you use the clob as a return type?
    Thanks!

  • How to get return value from java and read by other application?

    i want to read return value from java and the other application read it.
    for example:
    public class test_return {
        test_return(){
        public int check(){
            return 1;
        public static void main(String args[]){
           new test_return().check();
    }from that class i make as jar file. How to read the return value (1) by other application?
    thx..

    If your installer is requiring some process it invokes to return a particular value on failure, then the installer is seriously broken. There are a bazillion commands your installer could invoke, and any of them could fail, which in turn could invalidate the entire install process, and any of them could return any value on failure. The only value that's consistent (in my experience) is that zero means success and non-zero means failure, with specific non-zero values being different in different programs.
    About the only control you have over the JVM's exit code is that if your main method completes without throwing an exception, the JVM will have an exit code of 0, and if main throws an exception (either explicitly or by not catching one thrown from below), it will be non-zero. I'm not even sure if that's guaranteed, but I would guess that's the case.
    EDIT: I'm kind of full of crap here. If you're writing the Java code, you can call System.exit(whatever). But nonetheless, if your installer requires certain exit codes from any app--java or otherwise--you have a problem.
    Edited by: jverd on Oct 29, 2009 1:27 AM

  • Passing Tables back from Java Stored Procedures

    Thomas Kyte has written (in reference to
    trying to pass an array back from a stored
    function call):
    You can do one of two things (and both require the use of
    objects). You cannot use PLSQL table types as JDBC cannot bind to
    this type -- we must use OBJECT Types.
    [snip]
    Another way is to use a result set and "select * from
    plsql_function". It could look like this:
    ops$tkyte@8i> create or replace type myTableType as table of
    varchar2 (64);
    2 /
    Type created.
    ops$tkyte@8i>
    ops$tkyte@8i>
    ops$tkyte@8i> create or replace
    2 function demo_proc2( p_rows_to_make_up in number )
    3 return myTableType
    4 as
    5 l_data myTableType := myTableType();
    6 begin
    7 for i in 1 .. p_rows_to_make_up
    8 loop
    9 l_data.extend;
    10 l_data(i) := 'Made up row ' &#0124; &#0124; i;
    11 end loop;
    12 return l_data;
    13 end;
    14 /
    Function created.
    ops$tkyte@8i>
    ops$tkyte@8i> select *
    2 from the ( select cast( demo_proc2(5) as mytableType )
    3 from dual );
    COLUMN_VALUE
    Made up row 1
    Made up row 2
    Made up row 3
    Made up row 4 [Image]
    Made up row 5
    So, your JDBC program would just run the query to get the data.
    If the function "demo_proc2" cannot be called from SQL for
    whatever reason (eg: it calls an impure function in another piece
    of code or it itself tries to modify the database via an insert
    or whatever), you'll just make a package like:
    ops$tkyte@8i> create or replace package my_pkg
    2 as
    3
    4 procedure Make_up_the_data( p_rows_to_make_up in
    number ); 5 function Get_The_Data return myTableType;
    6 end;
    7 /
    Package created.
    ops$tkyte@8i>
    ops$tkyte@8i> create or replace package body my_pkg
    2 as
    3
    4 g_data myTableType;
    5
    6 procedure Make_up_the_data( p_rows_to_make_up in number )
    7 as
    8 begin
    9 g_data := myTableType();
    10 for i in 1 .. p_rows_to_make_up
    11 loop
    12 g_data.extend;
    13 g_data(i) := 'Made up row ' &#0124; &#0124; i;
    14 end loop;
    15 end;
    16
    17
    18 function get_the_data return myTableType
    19 is
    20 begin
    21 return g_data;
    22 end;
    23
    24 end;
    25 /
    Package body created.
    ops$tkyte@8i>
    ops$tkyte@8i> exec my_pkg.make_up_the_data( 3 );
    PL/SQL procedure successfully completed.
    ops$tkyte@8i>
    ops$tkyte@8i> select *
    2 from the ( select cast( my_pkg.get_the_data as mytableType
    ) 3 from dual );
    COLUMN_VALUE
    Made up row 1
    Made up row 2
    Made up row 3
    And you'll call the procedure followed by a query to get the
    data...
    I have tried this, and it works perfectly.
    My question, is what does the wrapper look
    like if the stored function is written
    in java instead of PL/SQL? My experiments
    with putting the function in java have been
    dismal failures. (I supposed I should also
    ask how the java stored procedure might
    look also, as I suppose that could be where
    I have been having a problem)
    null

    Thanks for the response Avi, but I think I need to clarify my question. The articles referenced in your link tended to describe using PL/SQL ref cursors in Java stored procedures and also the desire to pass ref cursors from Java to PL/SQL programs. Unfortunately, what I am looking to do is the opposite.
    We currently have several Java stored procedures that are accessed via select statements that have become a performance bottleneck in our system. Originally the business requirements were such that only a small number of rows were ever selected and passed into the Java stored procedures. Well, business requirements have changed and now thousands and potentially tens of thousands of rows can be passed in. We benchmarked Java stored procedures vs. PL/SQL stored procedures being accessed via a select statement and PL/SQL had far better performance and scaleable. So, our thought is by decouple the persistence logic into PL/SQL and keeping the business logic in Java stored procedures we can increase performance without having to do a major rewrite of the existing code. This leads to the current problem.
    What we currently do is select into a Java stored procedure which has many database access calls. What we would like to do is select against a PL/SQL stored procedure to aggregate the data and then pass that data via a ref cursor (or whatever structure is acceptable) to a Java stored procedure. This would save us a significant amount of work since the current Java stored procedures would simple need to be changed to not make database calls since the data would be handed to them.
    Is there a way to send a ref cursor from PL/SQL as an input parameter to a Java stored procedure? My call would potentially look like this:
    SELECT java_stored_proc(pl/sql_stored_proc(col_id))
    FROM table_of_5000_rows;
    Sorry for the lengthy post.

Maybe you are looking for