Executing a Stored Procedure passing Oracle Defined User Type

Hello All,
I am having problems in executing a SP from Java. Here is the detailed info of the prob I am facing.
I have a SP created which takes in a Table Type as one of the input parameter. This table type say "SERVICE" is of the Object Type "OBJ_SERVICETOMOVE".
Now I am writing a simple Java Clinet which executes the procedure. and below is the sample code I am pasting.
public class DBClient {
     public static void main(String args[])
          DBConnection dbclass = new DBConnection();
          dbclass.getConnection();
          //String movingOrder = args[0];
          ArrayList arrList = new ArrayList();
          arrList.add("10001");
          arrList.add("10002");
          arrList.add("10003");
          java.sql.Date date = null;
          try
               SimpleDateFormat objSDF = new SimpleDateFormat("dd/MM/yyyy");
               java.util.Date dtCcDate = (java.util.Date) objSDF.parse("02/01/2005");
               java.sql.Date localdate = new java.sql.Date(dtCcDate.getTime());
               date = localdate;
          catch(ParseException e)
               System.out.println("Parse Exception CAUGHT"+e.getMessage());
          combttmOE04ServicesToMove inputParam = new combttmOE04ServicesToMove(arrList);
          try
               OracleCallableStatement cs = dbclass.getCallableStatement("saveMovingOrder4Service(?,?,?)");
               cs.setInt(1,10);
               cs.setInt(2,date);
               cs.setObject(3,inputParam);
               dbclass.executeStoreProc();
          catch(SQLException e)
               e.printStackTrace();
          catch(Exception e)
               System.out.println("Exception CAUGHT"+e.getMessage());
The error I am getting is
java.sql.SQLException: Invalid column type
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java)
at oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java)
at oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java)
at DBClient.main(DBClient.java:84)
Can anyone of you advise me on this
Regards
Rags

Rags,
Have you looked at the JDBC sample code available from here:
http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/index.html
And the "how-to" documents, available from here:
http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jdbc/index.html
I once did something similar to what (I think) you are trying to do -- but unfortunately I lost that code when the hard-disk on my PC died. I do remember though, finding how to do it from the above-listed URLs.
Good Luck,
Avi.

Similar Messages

  • Execute a stored procedure in oracle sql developer

    I write a procedure in a package it compiles fine, but why when I execute it from right click the stored procedure and then click Ok, nothing happens, I cannot see from any screen if it executed or not , or is it successful or not?
    Thanks,

    What happens if you open the package in the editor and use the 'Execute' button on the toolbar?
    You should be prompted with a pop-up dialog asking you to select your procedure/function and provide the necessary input values and hit the 'Ok' button.

  • Oracle defined array type

    Hi,
    I am trying to pass an input parameter to a stored procedure as oracle defined array type. The input parameter will be stored as an array_varchar type which is defined by our own in our oracle 9i. Can anyone tell me how ? I've been looking for solution for 2 days and still dont know how.
    Thanks.
    yves

    The solution described in Passing Array of UDT or Collection as IN OUT using OracleDbType.InputOutput
    is working for me.
    Edited by: stzueger on Jan 2, 2012 10:32 AM

  • Error while executing a stored procedure from forms6i

    When I execute a STORED PROCEDURE from ORACLE DB 10g this procedure works perfectly fine.
    But when I execute the same from the FORMs 6i I get the following error:
    PDE-PLU022 Don't have access to the stored program unit
    XMLPARSERCOVER in schema CARE.
    where XMLPARSERCOVER is the class and
    CARE is the schema.
    Regards,
    Jignesh S

    I have tried this with both the owner of the schema and the intended user, -from both forms and directly.
    All rights was granted on the stored procedure. Since posting I have found that one of the tables that the procedure might insert into, was not explicitly granted to the intended user, and after rectifying that the error message went away.
    -however, the procedure now silently "finishes" without any evidence that it ever ran, if invoked from the forms application. When invoked from SQL Plus (or JDev, or Toad) it runs as expected.
    I have no public synonym for the procedure, -is that necessary?
    The stored procedure in question is implemented in java, and published as a stored procedure. It does rather heavy lifting, when running, using a view against another server , updating local tables and quite a lot of data validation/cleansing, and logging. All recourses are within the same schema.
    Any ideas?

  • Help required in executing the stored procedure and capturing the responce

    Hi,
    I have to execute a stored procedure in oracle database and if it successful then have to create a status IDOC.
    The stored procedure may throw an exception(it is not an out parameter), in such cases i should capture the exception as part of the response message and send this information while creating the status IDOC.
    i would like if the below is possible.
    As the stored procedure is not returning( this means if you execute the procedure manually it will display the result), will it be possible to capture the result which has the exception details?
    any direction to this will be highly appreciated.
    Many thanks.
    Regards,
    Rahul

    @Bhaskar,
    i need to execute the procedure by sending the input data from a file and capture the result after executing the procedure to create a status idoc
    im not sure how the provided links helps me here.
    i m not looking for any look ups. i would like to know is there any way that we can capture the result after executing the database procedure?
    Edited by: Rahul_10416 on Dec 5, 2011 10:07 PM

  • How to check which user has the privilege to execute a stored procedure?

    I am using Oracle 7 and I would like to check which user has the privilege to execute a stored procedure. How can I check it? Is there any view I can query for?
    Alex Hung

    Please check DBA_SYS_PRIVS.
    SQL> select * from dba_sys_privs
    2 where grantee='HARY';
    GRANTEE PRIVILEGE ADM
    HARY EXECUTE ANY PROCEDURE NO
    ....

  • Need sample source code for calling stored procedure in Oracle

    Hi.
    I try to call stored procedure in oracle using JCA JDBC.
    Anybody have sample source code for that ?
    Regards, Arnold.

    Thank you very much for a very quick reply. It worked, but I have an extended problem for which I would like to have a solution. Thank you very much in advance for your help. The problem is described below.
    I have the Procedure defined as below in the SFCS1 package body
    Procedure Company_Selection(O_Cursor IN OUT T_Cursor)
    BEGIN
    Open O_Cursor FOR
    SELECT CompanyId, CompanyName
    FROM Company
    WHERE CompanyProvince IN ('AL','AK');
    END Company_Selection;
    In the Oracle Forms, I have a datablock based on the above stored procedure. When I execute the form and from the menu if I click on Execute Query the data block gets filled up with data (The datablock is configured to display 10 items as a tabular form).
    At this point in time, I want to automate the process of displaying the data, hence I created a button and from there I want to call this stored procedure. So, in the button trigger I have the following statements
    DECLARE
    A SFCS1.T_Cursor;
    BEGIN
    SFCS1.Company_Selection(A);
    go_Block ('Block36');
    The cursor goes to the corresponding block, but does not display any data. Can you tell me how to get the data displayed. In the future versions, I'm planning to put variables in the WHERE clause.

  • 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.

  • . NET to call Oracle stored procedure, use an array of types of parameters

    . NET to call Oracle stored procedure, use an array of types of parameters
    Step1:(In the Oracle database define an array of types)
    CREATE OR REPLACE TYPE STRING_VARRAY AS VARRAY (1000) OF NVARCHAR2(255)
    Step2:
    CREATE OR REPLACE PROCEDURE Test
    (i_test in string_varray,o_result out int)
    IS
    BEGIN
    o_result:=i_test.count;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    NULL;
    WHEN OTHERS
    THEN
    o_result:=0;
    END arraytest;
    Step3:
    Use System.Data.OracleClient
    C# Code:
    OracleConnection conn = new OracleConnection("User Id=test;Password=test;Data Source=test");
    OracleCommand cmd = new OracleCommand("Test", conn);
    cmd.CommandType = CommandType.StoredProcedure;
    string[] str = new string[] { "11", "22" };
    OracleParameter p1 = new OracleParameter("i_test", OracleType.NVarChar);
    p1.Direction = ParameterDirection.Input;
    p1.Value = str;
    cmd.Parameters.Add(p1);
    OracleParameter p2 = new OracleParameter("o_result", OracleType.Int32);
    p2.Direction = ParameterDirection.Output;
    cmd.Parameters.Add(p2);
    int i = 0;
    try
    conn.Open();
    cmd.ExecuteNonQuery();
    i =(int) p2.Value;
    catch (Exception ex)
    finally
    conn.Close();
    Error:
    Execution Failed:ORA-06550:Line 1,Column 7:
    PLS-00306:Test parameters when calling the number or types of errors
    ORA-06550:Line 1,Column 7:
    PL/SQL:Statement ignored
    Edited by: user10133982 on Jun 4, 2009 7:13 AM

    . NET to call Oracle stored procedure, use an array of types of parameters
    The use of ODP.net(Oracle 10g), the error is still the same
    Step1:(In the Oracle database define an array of types)
    CREATE OR REPLACE TYPE STRING_VARRAY AS VARRAY (1000) OF NVARCHAR2(255)
    Step2:
    CREATE OR REPLACE PROCEDURE Test
    (i_test in string_varray,o_result out int)
    IS
    BEGIN
    o_result:=i_test.count;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    NULL;
    WHEN OTHERS
    THEN
    o_result:=0;
    END arraytest;
    Step3:
    ODP.NET(Oracle 10g)
    OracleConnection conn = new OracleConnection("User Id=test;Password=test;Data Source=test");
    OracleCommand cmd = new OracleCommand("Test", conn);
    cmd.CommandType = CommandType.StoredProcedure;
    string[] str = new string[2] { "11", "222" };
    cmd.ArrayBindCount=2;
    OracleParameter p1 = new OracleParameter("i_test", OracleDbType.NVarChar);
    p1.Direction = ParameterDirection.Input;
    p1.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
    p1.Value = str;
    p1.ArrayBindSize=new int[2]{2,3};
    p1.ArrayBindStatus = new OracleParameterStatus[2]{
    OracleParameterStatus.Success,
    OracleParameterStatus.Success
    cmd.Parameters.Add(p1);
    OracleParameter p2 = new OracleParameter("o_result", OracleDbType.Int32);
    p2.Direction = ParameterDirection.Output;
    P2.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
    p2.Value=0;
    cmd.Parameters.Add(p2);
    int i = 0;
    try
    conn.Open();
    cmd.ExecuteNonQuery();
    i =(int) p2.Value;
    catch (Exception ex)
    finally
    conn.Close();
    Error:
    Execution Failed:ORA-06550:Line 1,Column 7:
    PLS-00306:Test parameters when calling the number or types of errors
    ORA-06550:Line 1,Column 7:
    PL/SQL:Statement ignored
    Edited by: user10133982 on Jun 5, 2009 7:48 AM

  • URGENT: Java stored procedure on oracle 92 database is not working

    Hi,
    I am having an issue regarding java stored procedures. I have created a java class that uses the bouncycastleprovider ( bcprov-jdk13-141.jar ) to encrypt strings. I tested against the version of the java virtual machine that comes bundled with oracle and it works perfectly. I then used JDeveloper to load the class on the database with the resolve, noverify and order flags checked and it shows no errors but when I try to execute the stored procedure it throws the following exception:
    java.lang.ExceptionInInitializerError:
    java.lang.SecurityException: Cannot set up certs for trusted CAs: java.net.MalformedURLException: no protocol: US_export_policy.jar
    at javax.crypto.SunJCE_b.<clinit>(DashoA6275)
    at javax.crypto.Cipher.a(DashoA6275)
    at javax.crypto.Cipher.getInstance(DashoA6275)
    at RijndaelEnhanced.encrypt(RijndaelEnhanced.java:57)
    at RijndaelEnhanced.encrypt(RijndaelEnhanced.java:73)
    I loaded jce1_2_2.jar, sunjce_provider.jar, bcprov-jdk13-141.jar. Also replaced the US_export_policy.jar, local_policy.jar with the unrestrictive version. I add the security provider dinamically with a call to Security.insertProviderAt(new org.bouncycastle.jce.provider.BouncyCastleProvider(), 2);
    I also did a select on the user_objects table and all the classes are in VALID status.
    When I run my application using the java virtual machine that is located under C:\Oracle\oracli9i\jdk\jre\bin directory it works fine but when I try to execute on the database it won't work. I found a bug that was if the jce1_2_1.jar file existed in the C:\Oracle\oracli9i\jdk\jre\lib\ext directory ( even if it's extension is renamed ) it won't work because the certification file had expired but I don't know if this has anything to do with this error.
    Am I missing something?
    Please I need an urgent solution to this problem.
    Thanks in advance.
    Bruno Oliveira

    SomeoneElse wrote:
    Waaaaahhhhhhh!I was just thinking the same thing.... ya beat me to it...
    To the OP:
    As an up and coming DB Developer who now works for a small tech firm straight outta college, I can tell you for sure that you will definitely not get anywhere in your impatient life... look behind your back you miserable dude, your job might be in danger since ya got a bad attitude AND you can't figure out an error you are getting from a Java SP. So instead of helping you, I am going to simply tell you how you SHOULD act in a community of practice.
    1. Be nice when looking for help
    2. BE NICE WHEN LOOKING FOR HELP!!!
    Pretty simple right?
    Know what else is really simple? Looking at the topics of each board to make sure ya post in the right board! You people disgust me; somehow getting by in your professional career acting the way you do. I sure hope your "online" persona isn't a reflection of your real attitude towards people, almost pathetic and extremely immature.
    Sorry bout the rant, it is Friday, I know :) Didn't get my coffee this morning. Have a good one all!
    -Tim

  • Error while executing the stored procedure through sender JDBC adapter

    Hi All,
    I am getting below error while executing the stored procedure through sender JDBC adapter.
    Database-level error reported by JDBC driver while executing statement 'exec SapgetNextEntity 'SalesOrder''. The JDBC driver returned the following error message: 'com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.'. For details, contact your database server vendor.
    what is the problem? any idea to anyone...
    regards
    Ramesh

    hi Dharamveer,
    I am not getting below statement for your reply
    Try to use Refrence Cursor it will return u reference of resultset.
    I mention SP like this
    exec SapgetNextEntity 'SalesOrder'
    SapgetNextEntity -
    > SP Name
    SalesOrder----
    > Parameter I am passing...
    regards
    Ramesh

  • Executing a stored procedure using a button within a region

    Hello APEX Users:
    I have the task of creating a link within an apex region to execute a stored procedure from another schema using two arguments. What is the best method of executing a procedure in apex using a link or button? Thanks.
    Ben

    Stop posting follow-ups to closed/old threads.
    <li>Other users may ignore the thread as it appears to be closed
    <li>Your assumption that the questions are related may be incorrect, leading to confusion about the nature of the problem and potential solutions.
    <li>Watches on the thread may have expired, so the original participants may be unaware of the new post, or they may no longer be active on the forum
    <li>APEX Phone Test
    <li>You have no ability to mark posts as helpful or correct
    Post your question as a new thread, including the following information:
    <li>APEX version
    <li>DB version and edition
    <li>Web server architecture (EPG, OHS or APEX listener)
    <li>Browser(s) used
    <li>Theme
    <li>Templates
    <li>Region type
    <li>Links to related posts and threads using the methods in the FAQ.
    Your question has NOTHING to do with this thread.
    And update your forum profile with a better handle than "862509".

  • Incorrect Update Count by executing a stored procedure from Java

    Hi Guys,
    I am calling a stored procedure from the java program which is modifying the rows of a table. Now I want to know how many rows have been modified by executing the stored procedure. I am writing the following code for the purpose:
    OracleCallableStatement stmt =
    (oracle.jdbc.driver.OracleCallableStatement)con.prepareCall("{callsp_um_setForumID(?,?)}");
    stmt.setInt(1,101);
    stmt.setInt(2,666);
    n = stmt.executeUpdate();
    System.out.println(n + " row(s) updated");
    This procedure is actually modifying the table(When I query the databse it has modified 1 row). But it is returning a value 0 and is printing "0 row(s) updated".
    Is there a way by which I can find out the number of rows updated by executing the stored procedure?
    Thanks
    Sachin
    [email protected]

    I'm no expert on this, but I have a similar call where I fetch
    an Oracle REF CURSOR from a call to a stored function. If you
    fetch the cursor as an Object from your CallableStatement, you
    can then cast it to a ResultSet e.g.
    mystatement.executeUpdate();
    ResultSet rs = (ResultSet) mystatement.getObject(1);
    Then you should be able to loop through your ResultSet as usual.
    Good luck!
    Chris

  • Executing a stored procedure from an Ifs Program

    I have a need to execute a stored procedure in another schema
    within the same database, and I need to receive an OUT parameter
    to continue processing. The oracle.ifs.server.sql.IfsConnection
    is not in my class path. Can someone tell me which jar file to
    adde to my classpath to have this funcitonality that IFS claim.
    Regards,
    Jeff

    Guys I need help with this one as soon as possible.

  • Calling stored procedure in Oracle forms

    I have a stored procedure in Oracle which is declared as follows in the package
    SFCS1.Company_Selection(O_Cursor IN OUT T_Cursor, cls IN Varchar2);
    Where T_Cursor is defined as a Ref Cursor
    From the Oracle forms I'm using the following code
    SFCS1.Company_Selection(A,my_cls);
    go_block('Block50');
    Execute_Query;
    I get the error message "FRM40505:Oracle Error: Unable to Perform Query". If I hardcode the value of my_cls in the query it runs properly. Any solutions will be really helpful
    Further to this, I want to put the single quotes around a value (for eg. 'A') from a variable. For instance I'm getting a value from my_cls and for the output I want to surround it with the single quotes, can somebody tell me how to do it.
    Thanks in advance

    This is a bit of a roundabout way to do it? Try setting up the block data source as procedure and set the values in the property palette of the data block.
    e.g.
    Query Data Source Type = Procedure
    Query Data Source Name = SFCS1.Company_Selection
    Query Data Source Columns = (Whatever columns/items you have in your datablock)
    Query Data Source Arguments = Argument names are your ref cursor and your variable.
    Check out basing data blocks on Ref Cursors.
    HTHs
    L :-)

Maybe you are looking for