Calling a stored procedure of oracle 8 from java

hello,
i made a stored procedure as below in 1 program :
     String url = "jdbc:odbc:rjc1";
     Connection con = DriverManager.getConnection(url,"scott","tiger");
     Statement stmt = con.createStatement();
     String createProc =
          "Create procedure sp1 as select * from items order by iprice desc";
     stmt.executeUpdate(createProc);
in other program i have a code as below to retrieve the result of stored procedure :
CallableStatement cs = con.prepareCall("{call sp2}");
     ResultSet rs = cs.executeQuery();
the error message that i get is SCOTT.SP1 is invalid.
any help would be great.
thanx in advance.

hello :
1. i created procedure sp2 and called sp2.
2. sql statement that we created works fine on oracle - sql i have tested the same.
3. i did not create a separte userid or password in oracle i was using test account scott which is already present in oracle.
any thoughts please.

Similar Messages

  • SQLException while calling a Stored Procedure in Oracle

    Hi all,
    I am getting this error while calling a Stored Procedure in Oracle...
    java.sql.SQLException: ORA-00600: internal error code, arguments: [12259], [], [
    at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:207)
    at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:540)
    at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1273)
    at oracle.jdbc.ttc7.TTC7Protocol.fetch(TTC7Protocol.java:780)
    at oracle.jdbc.driver.OracleResultSet.next(OracleResultSet.java:135)
    at StoredProcedureDemo.main(StoredProcedureDemo.java:36)
    The Program is ...
    import java.sql.*;
    public class StoredProcedureDemo {
         public static void main(String[] args) throws Exception {
              Connection con = null;
              ResultSet rs = null;
              Statement st = null;
              CallableStatement cs = null;
              int i;
              try {
                   Class.forName("oracle.jdbc.driver.OracleDriver");
                   con = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:SHYAM","scott","tiger");
                   System.out.println("Got Connection ");
                   st = con.createStatement();
                   String createProcedure = "create or replace PROCEDURE Get_emp_names (Dept_num IN NUMBER) IS"
                             +" Emp_name VARCHAR2(10);"
                             +" CURSOR c1 (Depno NUMBER) IS"
                             +" SELECT Ename FROM emp WHERE deptno = Depno;"
                             +" BEGIN"
                             +" OPEN c1(Dept_num);"
                             +" LOOP"
                             +" FETCH c1 INTO Emp_name;"
                             +" EXIT WHEN C1%NOTFOUND;"
                             +" END LOOP;"
                             +" CLOSE c1;"
                             +" END;";
                   System.out.println("Stored Procedure is \n"+createProcedure);
                   i = st.executeUpdate(createProcedure);
                   System.out.println("After creating the Stored Procedure "+i);
                   cs = con.prepareCall("{call Get_emp_names(?)}");
                   System.out.println("After calling the Stored Procedure ");
                   cs.setInt(1,20);
                   System.out.println("Before executing the Stored Procedure ");
                   rs = cs.executeQuery();
                   System.out.println("The Enames of the given Dept are ....");
                   while(rs.next()) {
                        System.out.println("In The while loop ");
                        System.out.println(rs.getString(1));
              catch (Exception e) {
                   e.printStackTrace();
    Stored Procedure is ...
    create or replace PROCEDURE Get_emp_names (Dept_num IN NUMBER) IS
    Emp_name VARCHAR2(10);
    CURSOR c1 (Depno NUMBER) IS
    SELECT Ename FROM emp WHERE deptno = Depno;
    BEGIN
    OPEN c1(Dept_num);
    LOOP
    FETCH c1 INTO Emp_name;
    EXIT WHEN C1%NOTFOUND;
    END LOOP;
    CLOSE c1;
    END;
    Stored procedure is working properly on sql*plus(Oracle 8.1.5)) editor. But it is not working from a standalone java application. Can anyone please give me a solution.
    thanks and regards
    Shyam Krishna

    The first solution is to not do that in java in the first place.
    DDL should be in script files which are applied to oracle outside of java.
    Other than I believe there are some existing stored procedures in Oracle that take DDL strings and process them. Your user has to have permission of course. You can track them down via the documentation.

  • Calling SQL Stored Procedure using Oracle Gateway

    Hi
    Do you know how i can call a stored procedure with parameters from Oracle using oracle gateway?

    Don't know which gateway you are using. Only the transparent gateway for SQL Server and Sybase that have support for stored procedures.
    Take a look at case 7 which shows how to do this.
    Rem case7.sql
    Rem
    Rem Copyright (c) Oracle Corporation 2000. All Rights Reserved.
    Rem
    Rem NAME
    Rem case7.sql
    Rem
    Rem DESCRIPTION
    Rem SQL script which executes the demo case7 for the
    Rem Transparent Gateways
    Rem
    Rem NOTES
    Rem The database link GTWLINK should be created before you can
    Rem run this demo file
    Rem
    Rem MODIFIED (MM/DD/YY)
    Rem kpeyetti 11/09/00 - Created
    Rem
    SET ECHO ON
    DROP TABLE LOCAL_GTW_DEPT;
    CREATE TABLE LOCAL_GTW_DEPT (DEPTNO INTEGER, DEPTNAME VARCHAR2(14));
    SELECT * FROM LOCAL_GTW_DEPT;
    DECLARE
    DNAME VARCHAR2(14);
    BEGIN
    "GetDept"@GTWLINK(10,DNAME);
    INSERT INTO LOCAL_GTW_DEPT VALUES (10, DNAME);
    END;
    SELECT * FROM LOCAL_GTW_DEPT;

  • JDBC Passing ResultSet to a Stored Procedure in Oracle through Java

    I have following Stored Procedure written in Oracle.
    create or replace package types
    as
         TYPE NumCurType IS REF CURSOR;
         FUNCTION add_numbers(c2 IN NumCurType)
         RETURN NUMBER;
    END;
    CREATE OR REPLACE PACKAGE BODY types
    as
         FUNCTION add_numbers(c2 IN NumCurType)
         RETURN NUMBER
         IS
         v_sum number :=0;
         num_record num%rowtype;
         begin
         loop
         fetch c2 into num_record;
         v_sum:= v_sum + num_record.id ;
         dbms_output.put_line(v_sum);
         exit when c2%NOTFOUND;
         end loop;
         close c2;     
         return v_sum;
         end add_numbers;
    begin
    dbms_output.put_line('test');
    end;
    And the following java class to call the stored procedure.
    import java.io.*;
    import java.sql.*;
    class test
         public static void main(String arg[]) throws Exception
              Class.forName("oracle.jdbc.driver.OracleDriver");
              Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@localhost:1521:oracle","scott","tiger");
              Statement stmt = conn.createStatement();
              String sql = "select id from num";
              ResultSet rs = stmt.executeQuery(sql);
              System.out.println(rs);
              if(rs != null)
                   rs.next();
              CallableStatement cstmt = conn.prepareCall("{ ? = call types.add_numbers(?) }");
              cstmt.registerOutParameter(1,java.sql.Types.DOUBLE);     
         cstmt.setObject(2,rs,OracleTypes.CURSOR);                    
              cstmt.executeUpdate();
              System.out.println(cstmt.getObject(1));
              System.out.println("Procedure Exceuted");
    When I run the class I get following error
    java.sql.SQLException end of TNSData channel
    Can anybody help me in locating the error?

    Hi Jain,
    As far as I know, what you are attempting to do cannot be done. If I remember correctly, this question has been previously discussed on Oracle's "Technet" forums:
    http://technet.oracle.com
    There is no capability in the Oracle JDBC driver for translating a "ResultSet" to a REF CURSOR.
    You may also be able to find more details at the following Web sites:
    http://asktom.oracle.com
    http://metalink.oracle.com
    Good Luck,
    Avi.

  • Calling a stored procedure using Oracle Ole Db provider

    I am looking for an example of syntax used to call a stored procedure from VB.Net using the Oracle OleDB provider. I have been using the Microsoft provider MSDAORA but need to move to the Oracle provider due to upgrade. The syntax used with the MSDAORA provider does not work with the Oracle provider.

    Hi,
    Please refer to the Populate DataSet with Multiple REF Cursors Sample available at the following URL:
    http://otn.oracle.com/sample_code/tech/windows/ole_db/oledb92/index.html
    Check the PopulateProducts method available in the ViewProducts.cs file that call a database stored procedure "getProductsInfo" . This code is written in C# you may want to convert it to VB.NET syntax.
    Thanks,
    Jagriti
    OTN IDC Team.

  • Calling stored procedures in Sybase from java

    Hi,
    I am using the following stored procedure in Sybase
    use xyzdb
    go
    -- drop procedure if it already exist
    if object_id('up_name_select') is not null
    begin
    drop procedure up_name_select
    end
    go
    create procedure up_name_select
    @zid          numeric(7,0),
    @firstname     char(40),
    @lastname     char(40)
    as
    select zid,
    firstname,
    lastname
    from name
    where zid = @zid or
    (lastname like @lastname or firstname like @firstname)
    go
    -- update documentation records in object_docs
    delete object_docs
    from object_docs
    where object_name = "up_name_select"
    go
    insert into object_docs values("up_name_select","Selects records from the name table based upon the values of the input parameters.")
    go
    -- update documentation records in column_docs
    delete column_docs
    from column_docs
    where object_name = "up_name_select"
    go
    insert into column_docs values("up_name_select","@zid","System generated ID for an individual contact.")
    insert into column_docs values("up_name_select","@firstname","First name of the contact. SQL wild card characters are accepted.")
    insert into column_docs values("up_name_select","@lastname","Last name of the contact. SQL wild card characters are accepted.")
    go
    -- print success message and grant permissions
    if object_id('up_name_select') is not null
    begin
    print "Procedure up_name_select created."
    grant execute on up_name_select to developer_role
    end
    go
    This stored procedure selects the values from the table "name" for a given where condition (if I am not wrong).
    Can any one give me sample java code to select the records from the table "name" for a given zid.
    Thankyou in advance.
    Regards
    sgatl2

    calling stored procedures from java
    here is the sample code
    CallableStatement cs = con.prepareCall("{call selectlogin (?)}");
    cs.setString (1, "value");         
    ResultSet rs = cs.executeQuery ();
                while (rs.next ())
                //your code for display
                } more on gooooooogle
    http://www.google.com/search?q=calling+stored+procedures+from+java+with+sample+example&client=netscape-pp&rls=com.netscape:en-US

  • To call db2 stored procedure having parameters in java application

    Hi,
    I've created db2 stored procedure which is running perfectly on db2 server after giving a CALL to it. But when I tried to call this same stored procedure in java application, its reflecting with following error......
    com.ibm.db2.jcc.b.SqlException: [jcc][10100][10910][3.50.152] java.sql.CallableStatement.executeQuery() was called but no result set was returned.
    Use java.sql.CallableStatement.executeUpdate() for non-queries. ERRORCODE=-4476, SQLSTATE=null
    at com.ibm.db2.jcc.b.wc.a(wc.java:55)
    at com.ibm.db2.jcc.b.wc.a(wc.java:102)
    at com.ibm.db2.jcc.b.tk.b(tk.java:575)
    at com.ibm.db2.jcc.b.vk.yb(vk.java:136)
    at com.ibm.db2.jcc.b.vk.executeQuery(vk.java:114)
    at SPApplication.main(SPApplication.java:31)
    Here is the code.......
    import java.sql.*; public class SPApplication { public static Connection con; public static CallableStatement proc_stmt; public static ResultSet rs; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub try { Class.forName("DB2 DRIVER CLASS"); System.out.println("Class loaded....."); con = DriverManager.getConnection("jdbc:db2://localhost:PORTNO/" +                                   " DatabaseName", "username", "password"); System.out.println("Connection established....."); proc_stmt = con.prepareCall("call procedure_name(?)"); //IN Parameter proc_stmt.setInt(1, 5); System.out.println("Called procedure....."); rs = proc_stmt.executeQuery(); /******** THIS IS LINE NO. 31 *********/ while (rs.next()) {                              // Fetching rows one by one over here } proc_stmt.close(); rs.close(); con.close(); } catch (ClassNotFoundException cnfe) { cnfe.printStackTrace(); } catch (SQLException sqle) { sqle.printStackTrace(); } finally { /* try { proc_stmt.close(); rs.close(); con.close(); } catch (SQLException sqle) { sqle.printStackTrace(); } */ } } }
    Please correct me, if I am wrong at any point in my application..
    I would really appreciate for resolving my problem.
    Thanks,
    Manasi N.

    Hi jschell ,
    Firstly, I tried out with execute() and getMoreResults() to check if the statement is returning result set. - Its returning "null" only.
    Secondly, I tried with following one by one :
    1. Find a new jdbc driver
    2. Write a different stored procedure.I am using DB2 Express edition - DB2 v9.7.0.0
    I have the required jar files - i)db2jcc.jar ii) db2jcc_license_cu.jar
    From these I found the available jdbc drivers as -
    i) com.ibm.db2.jcc.DB2Driver
    ii) COM.ibm.db2os390.sqlj.jdbc.DB2SQLJDriver
    iii) com.ibm.db2.jcc.uw.DB2StoredProcDriver
    I tried out my code by using each of these drivers, but still returning result set as null.
    Moreover, I changed my stored procedure which has cursor returning result set. In this case also, result set is null.
    Code snippet for this SP is -
    30             Class.forName("com.ibm.db2.jcc.uw.DB2StoredProcDriver");
    31             System.out.println("Class loaded....");
    32             con = DriverManager.getConnection
    33                 ("jdbc:db2://localhost:portno/dbName", "user", "password");
    34             System.out.println("Connection established....");
    35
    36             proc_stmt = con.prepareCall("call javaSP()");
    37            
    38             System.out.println("Called stored procedure....");
    39            
    40             proc_stmt.execute();
    41             //proc_stmt.executeUpdate();
    42             //rs = proc_stmt.getResultSet();
    43
    44             System.out.println("Query executed....");
    45            
    46             if ((proc_stmt.getMoreResults() == false) &&
    47                     (proc_stmt.getUpdateCount() == -1)) {
    48                 System.out.println("No more result sets");
    49             }o/p is (for every mentioned above jdbc driver) :-
    Class loaded....
    Connection established....
    Called stored procedure....
    Query executed....
    No more result sets..
    The o/p is always "No more result sets"
    What else can be tried out to retrieve the result set from stored procedure from Java application? And the most important, these same stored procedures are returning result sets on db2 server after calling them.
    Thank you,
    Manasi.N
    Edited by: Manasi.N on Apr 14, 2010 12:27 AM
    Edited by: Manasi.N on Apr 14, 2010 12:28 AM

  • Calling DB2 Stored procedure(with parameters) from powershell

    Hi 
    I am trying to call a DB2 stored procedure that has parameters from Powershell scrip and I am not able to can some one help me here?
    $ServerName = 'XXXX'
    $dbalias='XXXXX'
     $conn_string = "Provider=IBMDADB2;DBALIAS=$dbalias;Uid=;Pwd=;"
     $conn = new-Object system.data.Oledb.OleDbconnection
     $conn.ConnectionString = $conn_string
     $conn.open()
     $query="CALL DBID_CONTROL.GET_TABLE_MAINT_CTL(?,?,?,'MSAS','DATABASE_CONNECTIONS_CUBE','CUBE_PARTITION');"
     $cmd = new-Object system.data.Oledb.OleDbcommand($query,$conn)
      $ds=New-Object system.Data.DataSet
     $da=New-Object System.Data.OleDb.OleDbDataAdapter($cmd)
      $da.Fill($ds) [int]$cur_utc_date_key = $ds.Tables[0].Rows[0][0]
     $cur_utc_date          = $ds.Tables[0].Rows[0][1]
     ###list current date key & current date values
     write-output "current date key value is $cur_utc_date_key"
     write-output "current date value is $cur_utc_date"
     write-output " "
    Thanks

    Hi 
    This is the error message i get when i run the script
    Exception calling "Fill" with "1" argument(s): " CLI0100E  Wrong number of parameters. SQLSTATE=07001"
    At line:45 char:10
    +  $da.Fill <<<< ($ds)
        + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : DotNetMethodException

  • Problem Calling MaxDB stored procedure with output from MII Query template

    Hi,
    I am using Max DB Database studio to write stored procedure, I am calling stored procedure from MII Query using CALL statement.
    Can anyone guide me how to pass output values of stored procedure.
    Examlpe::
    call ProcName('[Param.1]','[Param.2]','[Param.3]','[Param.4]','[Param.5]', :isSuccess, :Trace)
    In the above line of code I am not able to get the output values of stored procedure that is isSuccess and Trace values in Query template when executed. But same thing I get when executed in Database studio.
    How do I call with outputs for any stored procedure in MII.
    Any help would be appriciated.
    Thanks,
    Padma

    My call statement is like this
    call RESULTDATA_INSERT('[Param.1]','[Param.2]','[Param.3]', :isSuccess, :Trace)
    I am able to insert record in DB, But I am not getting output values in Query template.I have done this in Fixed Query, when I execute it throws me "Fatal error as Loaded content empty".
    I tried giving select below call but it dont work.
    Regards,
    Rao

  • Calling a stored procedure from Reports

    I am trying to call a stored procedure using oracle reports in the afterparameter code. My code is:
    v_ain := sp_get_ain(:P_session_id);
    Can someone help me out by telling what is wrong. I keep getting an error stating that sp_get_ain needs to be declared.?!

    I am creating a function and a stored procedure and calling them
    in afterparameter report trigger.
    -------------------Create function ----------------
    create or replace function get_name( emp_id number) return varchar2 is
    v_name varchar2(20);
    begin
    select name into v_name
    from sample_table
    where employ_id = emp_id ;
    return(v_name); ---------This is the way to return value from function.
    exception
    when no_data_found then
    return('Name not found.');
    when others then
    return('Other error found.');
    end ;
    ==================================================================================
    ------------------------Create procedure ------------------------------------
    create or replace procedure get_name( emp_id number, return_name out varchar2) is
    v_name varchar2(20);
    begin
    select name into v_name
    from sample_table
    where employ_id = emp_id ;
    return_name := v_name ; --Assign out parameter value from procedure.
    exception
    when no_data_found then
    return_name := 'Name not found.';
    when others then
    return_name := 'Other error found.';
    end ;
    ============================================================================
    -----------------Call function and procedure from report ---------------------
    In formula column or any report trigger you can use this code.
    v_function_return_name varchar2(20);
    v_procedure_return_name varchar2(20);
    v_employ_id number(10);
    begin
    v_employ_id := 101 ;
    v_function_return_name := get_name(v_employ_id ); --- call function
    get_name(v_employ_id , v_procedure_return_name ); -- call procedure
    end;
    Here v_function_return_name has same value as v_procedure_return_name,
    these are the values returned from function and procedure.
    --Anita

  • How to call a stored procedure from servlet?

    Hi all
    We are developing a project in servlet which needs to call a stored procedure in oracle 8i database.How to make a call? Whether can i get any data from the database using STORED PROCEDURE
    THANKS IN ADVANCE
    kamalakannan

    Hello,
    You can do an HTTP call from a store procedure using thre UTL_HTTP package; so you should be able to call your servlet this way.
    See UTL_HTTP documentation
    Regards
    Tugdual Grall

  • Without calling stored procedure or functions from database

    Hi,
    I am using Jdeveloper 11.1.1.5.0.
    =>How to do PL/SQL procedures and functions in ADF without calling stored procedure or function from DB?

    S, PL/SQL procedures and functions are done in Application Module class or in managed bean..By calling the stored procedures or functions from DB.
    But I am asking how to do if DB doesn't have any procedures,triggers and functions.

  • Calling packaged stored procedure from Java

    Hi All,
    I'm trying to call a stored procedure from Java but I'm having
    problems with registrating the output parameter. I'm getting
    the error: Conflicting parameters.: sqltype=2003
    This is the stored procedure which is located in a package in
    the Oracle database:
    package Pack_GetAgencyInformation as
    Type InfoType is record ( agen_code varchar(3), agen_designation
    varchar(30), agen_adresse varchar(60), agen_tel varchar(12) );
    function GetAgencyInformation( P_AGENCE VARCHAR )
    return Pack_GetAgencyInformation.InfoType
    end Pack_GetAgencyInformation;
    This is the Java source from where I'm calling the procedure:
    //DriverManager.registerDriver (new
    oracle.jdbc.driver.OracleDriver());
         Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection
    ("jdbc:oracle:thin:@164.48.69.125:1521:ventes", "system", "*****
    // @machineName:port:SID,
    userid, password
    CallableStatement cs = conn.prepareCall("{ ? = call
    Pack_GetAgencyInformation.GetAgencyInformation( ? )}");
         try {
              cs.registerOutParameter( 1,
    oracle.jdbc.driver.OracleTypes.ARRAY);
         } catch (SQLException e) {
              e.printStackTrace();
         cs.setString(2, "001" );
         //ResultSet rset = cs.executeQuery();
    The stacktrace:
    java.sql.SQLException: Parametertypen conflicteren.:
    sqlType=2003
    at oracle.jdbc.dbaccess.DBError.throwSqlException
    (DBError.java:168)
    at oracle.jdbc.dbaccess.DBError.throwSqlException
    (DBError.java:210)
    at
    oracle.jdbc.driver.OracleCallableStatement.registerOutParameter
    (OracleCallableStatement.java:220)
    at
    oracle.jdbc.driver.OracleCallableStatement.registerOutParameter
    (OracleCallableStatement.java:350)
    at dbAccess.main(dbAccess.java:25)
    I think it has to do with the type InfoType which is created in
    the Stored Procedure. I'm absolute no Oracle expert and I
    prefer not to make changes to the Oracle database. So any
    solution in Java is welcome!
    BR, H.Rietman

    I managed to get it to work only by changing the stored
    procedure. I have changed the return type record to a Ref
    Cursor type (had to change alot of code for this). It seams
    that Oracle JDBC drivers DON'T support the Record type as a
    return type.
    So the next question is: is it possible to typecast a record
    type to a ref cursor type in Oracle. In this way I can easily
    change the return type for the stored procedures.
    /Harald

  • Calling invalid stored procedure from java

    Will the stored procedure which is invalid get re-compiled automatically when called from a java program?
    1.a stored procedure is invalid (oracle 9i)
    2.calling the stored procedure from a java program
    3.what will happen a.oracle recompiles the stored procedure
    b.returns an sql exception
    what happens,kindly help
    drop your mail to [email protected]
    Keep Smiling and Mailing,
    Vijay Anand Natesan.

    thank you ..Kindly let me know if any of your friends have tried this

  • Calling Stored procedure in Oracle 11g from Oracle forms developer 6i

    We have Oracle 11g (11.1.0.7.0 ) database (64 bit) installed on Windows Server 2008.
    In this database, we have stored procedure ABC(arg1) which is accesing a table in another instance through DB LINK. If we EXECUTE this procedure from SQL/TOAD. It runs successfully and generates the desired output.
    If we write the contents of the stored procedure in the PROGRAM UNIT / ANY TRIGGER in FORM 6i then also, It runs successfully and generates the desired output.
    It is also mentioned, that if we try to use any table in the same instance (and not through DBLINK) then it works fine.
    However, if we try to call this stored procedure (which is  accesing a table in another instance through DB LINK) from  ORACLE FORMS  6i  in WHEN-BUTTON-PRESSED trigger then the FORM BUILDER gets hanged while compiling the form developed in FORMS 6i.
    Please provide a solution to this problem.
    THANKS IN ADVANCE.
    Hemant Singh.
    Asstt. Manager(IT)
    Software development team.

    Forms 6i was never meant to run against a 11g database, this was not tested and is also not supported.Well, that is not completely true. Developer 6i is supported against a 11g database, but only for Oracle Apps R11. That means that for most other customers (not Apps) Forms 6i will work against an 11g database. However, only Apps R11 is supported, and patches are only created specifically for Apps. We are also running Forms 6i against an 11g database without (well, minor) problems.
    In this case, you need to find a solution. You can try to put the stored procedure in a package. The package body, with the reference to the remote table, will be hidden from Forms this way.

Maybe you are looking for