Calling stored procedure via java

Hi all,
i have a problem calling a stored procedure in my java code. I found an example at OTN which seems not to be correct. I know there had been a lot of posting regarding this isue but i did not find the solution.
I had the following VB-code to translate to java:
Set k = Server.CreateObject("ADODB.command")
With k
.activeconnection = Db
.CommandType = 4
.CommandText = "Get_SK"
Set vret = .createparameter("vRet", 131, 2) 'Output
.Parameters.append vret
.Execute
End With
In my java code:
CallableStatement sproc_stmt = null;
try {
sproc_stmt = lsession.connection().prepareCall("{ ? = call TCSDBOWNER.Get_SK}");
sproc_stmt.registerOutParameter(1,OracleTypes.NUMERIC);
sproc_stmt.setFetchSize(10);
sproc_stmt.execute();
The call generates an id for inserting new rows in the DB. executing the code shown above i got the following error:
wrong number or types of parameter/arguments
Is there anybody who can help me? Best regards,
ak

Hi again,
this was really ugly:
Re: Executing stored procedure via java
Thanks all, regards,
ak

Similar Messages

  • Error while calling stored procedure from Java

    Hi Guys,
    How are you everybody? I hope everything is goin fine on your side. I have one issue in PL/SQL while calling below stored procedures from Java.
    Problem Description: We have a stored procedure PROCEDURE BULK_INSERTS (
    V_SESSION_ID_TAB IN T_SESSION_ID_TAB_TYPE,
    V_SERVICE_TYPE_TAB IN T_SERVICE_TYPE_TAB_TYPE,
    V_SERVICE_LOCATION_TAB IN T_SERVICE_LOCATION_TAB_TYPE,
    V_SERVICE_CALL_NAME_TAB IN T_SERVICE_CALL_NAME_TAB_TYPE,
    V_SERVICE_CALL_START_TIME_TAB IN T_SERVICE_CALL_ST_TAB_TYPE,
    V_SERVICE_CALL_END_TIME_TAB IN T_SERVICE_CALL_ET_TAB_TYPE,
    V_SERVICE_CALL_DURATION_TAB IN T_SERVICE_CALL_DUR_TAB_TYPE,
    V_STATUS_TAB IN T_STATUS_TAB_TYPE,
    V_NOTES_TAB IN T_NOTES_TAB_TYPE
    ) and we are getting ora errors while calling this stored procedure from java.
    All tab types are declared locally, at package level.
    Here is error which occur while calling this sp:
    {call BULK_PKG.BULK_INSERTS(?,?,?,?,?,?,?,?,?)}
    And the parameter types we are using are:
    SESSION_ID - NUM_TAB_TYPE
    SERVICE_TYPE - VAR_TAB_TYPE
    SERVICE_LOCATION - VAR_TAB_TYPE
    SERVICE_CALL_NAME - VAR_TAB_TYPE
    SERVICE_CALL_START_TIME - DATE_TIME_TAB_TYPE
    SERVICE_CALL_END_TIME - DATE_TIME_TAB_TYPE
    SERVICE_CALL_DURATION - NUM_TAB_TYPE
    STATUS - VAR_TAB_TYPE
    NOTES - VAR_TAB_TYPE
    And the Exception stack trace is:
    ERROR (com.att.retail.r2d2.persistence.dao.ExternalServiceCallDAO.saveExternalServiceCallInfo(ExternalServi
    ceCallDAO.java:143)@ExecuteThread: '252' for queue: 'weblogic.kernel.Default') {Error attempting to save collected ESC data}
    java.sql.SQLException: ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
    at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:112)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:173)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413)
    at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1030)
    at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:191)
    at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:944)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1222)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3381)
    at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3482)
    at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:3856)
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1373)
    at weblogic.jdbc.wrapper.PreparedStatement.execute(PreparedStatement.java:98)
    at com.att.retail.r2d2.persistence.dao.ExternalServiceCallDAO.doBulkInsert(ExternalServiceCallDAO.java:220)
    at com.att.retail.r2d2.persistence.dao.ExternalServiceCallDAO.saveExternalServiceCallInfo(ExternalServiceCallDAO.java:138)
    Please help my guys out of this. I will really appreciate all suggestions and advices.
    Thank you everybody.

    I am trying to pass parameter to test my procedure but it is giving this error : ORA-06531: Reference to uninitialized collection
    ORA-06512: at line 12
    Here is example for my test procedure:
    declare
    v_session_id_tab SESSION_ID_TAB_TYPE;
    v_service_type_tab SERVICE_TYPE_TAB_TYPE ;
    v_service_location_tab SERVICE_LOCATION_TAB_TYPE ;
    v_service_call_name_tab SERVICE_CALL_NAME_TAB_TYPE;
    v_service_call_start_time_tab SERVICE_CALL_ST_TAB_TYPE;
    v_service_call_end_time_tab SERVICE_CALL_ET_TAB_TYPE;
    v_service_call_duration_tab SERVICE_CALL_DUR_TAB_TYPE;
    v_status_tab STATUS_TAB_TYPE;
    v_notes_tab NOTES_TAB_TYPE;
    begin
    v_session_id_tab(1) := 1;
    v_service_type_tab(1) := 'db';
    v_service_location_tab(1) := 'local';
    v_service_call_name_tab(1) := 'Name of call';
    v_service_call_start_time_tab(1) := SYSDATE;
    v_service_call_end_time_tab(1) := SYSDATE;
    v_service_call_duration_tab(1) := 100;
    v_status_tab(1) := 'Z';
    v_notes_tab(1) := 'NOTES';
    BULK_INSERTS (v_session_id_tab,v_service_type_tab, v_service_location_tab,v_service_call_name_tab,v_service_call_start_time_tab,v_service_call_end_time_tab,
    v_service_call_duration_tab, v_status_tab, v_notes_tab);
    end;
    I declare all types at schema level.
    Please give your comments.
    Thank you

  • Calling stored procedure from Java raises ORA-1722 exception

    Hi,
    As the title says, when I call the stored procedure from java I got the exception ORA-1722 (invalid number) but I've checked and rechecked my procedure on SQL-Developer and It's alright it works nice and clean !
    What's happening? is there something I'm missing?
    The way I call the stored procedure is:
        public void execProcedure(String procedure) {
            CallableStatement cs;
            try {
                cs = conn.prepareCall(procedure);
                cs.execute();
            } catch (SQLException ex) {
                Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
         where
        String procedure = "{call validateinfo}"I really need help on this, it's frustraiting me 'cause I need to finish a system but this little big problem is killing me ...
    Thanks any advice is very welcome :)

    Thanks for your help. Haven't tested the SP with a DB access client... which one do you recommend to use?
    The SP is the following:
    create or replace
    PROCEDURE validateInfo IS
      var number;
    BEGIN
      UPDATE temp_desarrollo
      SET status = '1';
      COMMIT;
      // Some string validations ...
      //This one just checks if the value of "monto" is a number
      //This update goes good
      UPDATE temp_desarrollo tmp
      SET cve_status = Decode(cve_status, NULL, '15', cve_status||',15')
      WHERE IsNumber(tmp.monto) = 'F';
      COMMIT;*/
      //This one just checks if the value of "monto" is greater than 0
      //if not, change de add to cve_status an errorValue
      UPDATE temp_desarrollo tmp
      SET cve_status = Decode(cve_status, NULL, '14', cve_status||',14')
      WHERE (cve_status NOT LIKE '%15%' OR cve_status IS NULL)
      AND to_number(tmp.monto) <= 0;
      COMMIT;
      //More string validations
      EXCEPTION
        WHEN OTHERS THEN
          var := SQLCODE;
          insert into excepciones values(to_char(var));
    END;I've deleted much code from the SP since I know there's nothing to do with the excepcion, just that UPDATE statement is the one giving me the exception.
    If those two UPDATES statements work with the same field (monto) why the first one is succeding and the second one not?
    Cheers,
    Federico
    P.S. the "isNumber" function is as follows, just in case.
    create or replace
    function IsNumber(val1 varchar2) return varchar2 is
      n number := null;
    begin
      n := to_number(val1,'9999999999999999.99');
        return 'T';
      exception
        when others then
          return 'F';
    end;

  • Calling Stored Procedures from JAVA Application

    Hi all,
    i am using JDeveloper 3.2.2 for creating a DB Application that
    uses Oracle8i as DB Server.
    One approach of the application is to only use PL/SQL Stored
    Procedures to write Data back to the DB.
    Some of the stored procedures expect more than 20 parameters.
    I want to know if there is a better way to call such a stored
    procedure from Java than using a CallableStatement and setting
    its 20 parameters.
    Another reason why the way above isnt possible for me is that
    i need a dynamic way to set the parameters of the stored
    procedure.
    A solution for that dynamic way i could think of is to get
    the information of the stored procedure by using some functions
    of DatabaseMetaData and than use this information to map the
    parameters with their respective variables in the java
    application.
    The best argument against this way is that it would be time and
    performance consuming.
    So could anybody tell me a solution to call PL/SQL stored
    procedures from java which is better than doing something like:
    String calString = "{Call myStoredProc(";
    while(counter < 22) {
    params += "?";
    if(counter<21) params += ",";
    counter++;
    calString += params + ")}";
    try {
    CallableStatement cs = session.prepareCall(calString);
    } catch(SQLException ex) { ... }
    cs.setString(1, var1);
    cs.setString(1, var2);
    And that for every Stored Procedure i want to call ?!?
    Any help or direction-leading would be really appreciated.
    Tank you much.
    MfG,
    Oliver Bankel

    Hi Oliver,
    If you your Stored Procedures were in Java and seamlessly
    integrated with your Java application would that make your life
    easier?
    I don't know if this is a practical or acceptable solution in
    your environment but it would certainly solve all of your issues
    and provide your with a couple of nice advantages. Scalability
    and platform independence are just a couple I could think of.
    There is a tool called in2j (see http://www.in2j.com) which will
    automatically migrate your PL/SQL Stored Procedures into Java.
    You can download a copy of the tool and migrate your PL/SQL to
    Java with no upfront costs. If you're happy with the generated
    Java and want to deploy it, the migration fee falls due - simple.
    Hope this helps.
    Elton

  • How to call stored procedures from java program?

    I have tried to run a program that calls a stored procedure on MySQL
    server version 5.0.17 by using connector/j 5.0, but it always fails on the
    statement: con.preparecall() ,
    have looked on the internet and found out that people can all mysql
    stored procedure all right in their programs, really dont know what's
    wrong with this small peiece of code:
    import java.sql.*;
    public class TestDB {
          // procedure being called is:
         CREATE PROCEDURE `dbsaystorm`.`getsite` ()
         BEGIN
            select  name  from tblsite;
         END
         public static void main(String[] args) {
              try  {
                  //Class.forName("org.gjt.mm.mysql.Driver");
                  Class.forName("com.mysql.jdbc.Driver");
                  Connection con = DriverManager.getConnection("jdbc:mysql://localhost/dbname",
                            "user", "pwd");
           * executing SQL statement here gives perfect correct results:
            // PreparedStatement ps = con.prepareStatement("select name from tblsite");      
            // ResultSet rs =ps.executeQuery();
                  // but in stored procedure way...
                  //it fails here on this prepare call statement:             
                  CallableStatement proc = con.prepareCall("call getsite()");
                  ResultSet rs =proc.executeQuery();                      
                  if (rs == null) return;                                      
                  while (rs.next()){                 
                      System.out.println("site name is: "+ rs.getString(1));                                
                  rs.close();
              } catch (SQLException e) {e.printStackTrace();}
               catch (Exception e) {e.printStackTrace();}         
    }it always gives this exception:
    java.lang.NullPointerException
         at com.mysql.jdbc.StringUtils.indexOfIgnoreCaseRespectQuotes(StringUtils.java:959)
         at com.mysql.jdbc.DatabaseMetaData.getCallStmtParameterTypes(DatabaseMetaData.java:1280)
         at com.mysql.jdbc.DatabaseMetaData.getProcedureColumns(DatabaseMetaData.java:3668)
         at com.mysql.jdbc.CallableStatement.determineParameterTypes(CallableStatement.java:638)
         at com.mysql.jdbc.CallableStatement.<init>(CallableStatement.java:453)
         at com.mysql.jdbc.Connection.parseCallableStatement(Connection.java:4365)
         at com.mysql.jdbc.Connection.prepareCall(Connection.java:4439)
         at com.mysql.jdbc.Connection.prepareCall(Connection.java:4413)
         at saystorm.server.data.database.TestDB.main(TestDB.java:29)
    where have I gone wrong?
    when I commented out the statement that makes the procedure call and call preparedstatement to execute SQL select statement, it gave perfectly correct result.
    it looks like there is no problem with java prog accessing MYSQL server database, but the it seems that it's just java can't call stored procedure stored on the mysql server version 5.
    can it or can't it? if it can, how is that accomplished?

    It is a bug in the driver because it shouldn't be
    returning that exception (null pointer) even if you
    are doing something wrong.
    Are you using the latest version of the driver?
    The stored procedure runs when you run it from the
    gui/command line using a MySQL tool - correct?
    As suggested you should be using the brackets. What
    is the data type of the 'name' field?
    You could try returning another value like one of the
    following
    select 1, name from tblsite;
    select name, 1 from tblsite;
    That might get around the bug
    Additionally try just the following...
    select 'test' from tblsite;yes, the driver used is in connector/j 5.0--the lastest one, and the
    procedure can run correctedly at either command line or GUI mode
    with no problem whatsoever, the returned data type is string type,
    I have not got the chance to test it again with those values you
    suggested, as I have abandoned the laptop I used to write that code
    initately. There have been some other really weird cases happened on
    that computer. I guess that must be something wrong with the JVM
    installed on it, it was upgraded from jre5.0.04 to 06, and to 09.
    something within hte JVM must have been messed up(the only reasonable
    explanation). Because the same code runs correctly on my new laptop,
    using the same environment: jvm 5.0_09, mysql 5.0.18, connector/J 5.0.
    that old laptop really was a nightmare.

  • Calling stored procedure from java...

    Hello,
    I've got a stored procedure that works correctly if I call it in Toad like:
    declare
    c CLOB;
    BEGIN
    GETLOCATIONSVOXML (c, '0087890', 8, 2007);
    END;
    no problems there however I'm trying to call it from java..
    public String getDALocations(String inEmplid, Date weekEndDate ) throws Exception {
              Connection connection = null;
              Clob loc;     
              String rtnSt = "";
              SimpleDateFormat yy = new SimpleDateFormat("yyyy");
              SimpleDateFormat ww = new SimpleDateFormat("ww");     
              try     {
                   connection = getConnection();           
                   CallableStatement  cs = connection.prepareCall(SQL_GETDALOCATIONXML);
                   cs.registerOutParameter(1,oracle.jdbc.driver.OracleTypes.CLOB);
                   cs.setString(2, inEmplid);
                   cs.setString(3, ww.format(weekEndDate));          
                   cs.setString(4, yy.format(weekEndDate));               
                   cs.execute();
                   loc = (Clob)cs.getClob(1);
                   rtnSt = "<node label='locations'>" + loc.getSubString(1,(int)loc.length()) + "</node>";
                   cs.close();
                    log.debug("retrieved xml locations");
              catch ( SQLException e ){
                   log.error("LocationDAO.getDALocations() failed", e);
                   throw new Exception(e);
              }     finally     {             
                   releaseConnection(connection);
    return rtnSt;          
    [pre]
    I'm getting the <node label='locations'></node> back, but nothing in between..
    Anyone offer any suggestions or ideas I can try? I'm wondering if the data in Oracle is being read incorrectly.. Is there anyway I can check that?
    Thanks so much!
    Thanks!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    aha! seems to be a problem with my proc...
    select c_schedulestatusid as status
    from schedule_status
    where location = 4131
    and week = 11
    and year = 2007
    [pre]
    part of my proc is returning null.. arg stupid error...                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Taking control back while calling stored procedure using java programme

    I have stored procedure to load data. This procedure is invoked by java program.
    The stored procedure take around 10 to 15 minutes to do complete loading of database. I want to write stored procedure when it starts loading of database at the same return the control to calling java programme so that java program can do other operation i.e. java program can not wait for control back from stored procedure.
    In short stored procedure runs in background and return control back to java program when stored procedure is invoked. Is it possible then How we can achieve this.

    U can acheive this using Java Threads. Create a thread submit this loading job. Once you submit the thread, you will get the control back to do other stuff.
    Documentation:
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Thread.html
    -aijaz

  • Executing stored procedure via java

    Hi all,
    i have a problem calling a stored procedure in my java code. I found an example at OTN which seems not to be correct. i had the following VB-code to translate to java:
    Set k = Server.CreateObject("ADODB.command")
    With k
    .activeconnection = Db
    .CommandType = 4
    .CommandText = "Get_SK"
    Set vret = .createparameter("vRet", 131, 2) 'Output
    .Parameters.append vret
    .Execute
    End With
    In my java code:
    CallableStatement sproc_stmt = null;
    try {
    sproc_stmt = lsession.connection().prepareCall("{ ? = call TCSDBOWNER.Get_SK}");
    sproc_stmt.registerOutParameter(1,OracleTypes.NUMERIC);
    sproc_stmt.setFetchSize(10);
    sproc_stmt.execute();
    The call generates an id for inserting new rows in the DB. executing the code shown above i got the following error:
    wrong number or types of parameter/arguments
    Is there anybody who can help me? Best regards,
    ak

    Hi,
    thanks for your reply.
    I have the description of this procedure (As you can see in my posting above) So it is definetly a procedure with one input parameter.
    Yes ist it a callable statement as the other one before. So the first one:
    CallableStatement sproc_stmt = lsession.connection().prepareCall("{call Get_SK(?)}");
                   sproc_stmt.registerOutParameter(1,Types.NUMERIC,1);
    ResultSet sproc_result = sproc_stmt.executeQuery();
    Works fine. No more problems with that. It is a procedure with one OUT_PARAMETER and no INPUT_PARAMETER.
    So, the only thing to change (I thought is):
    sproc_stmt = lsession.connection().prepareCall("{ call Get_SKS(?,?)}");
                   sproc_stmt.setInt(2,1);
                   sproc_stmt.registerOutParameter(1,OracleTypes.NUMERIC);
    ResultSet sproc_result = sproc_stmt.executeQuery();
    But this seems not that obvious. I got an error:
    java.sql.SQLException: ORA-01722: invalid number
    ORA-06512: at "SYS.DBMS_SYS_SQL", line 826
    ORA-06512: at "SYS.DBMS_SQL", line 39
    ORA-06512: at "TCSDBOWNER.GET_SKS", line 44
    ORA-06512: at line 1
    So it seems something is wrong with this output parameter!?
    Any more help? Regards,
    ak

  • 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

  • Problem in calling Oracle stored procedure from Java.

    I am trying to invoke the Oracle stored procedure from Java. The procedure does not take any parameters and does not return anything. If I call it from SQL prompt it is working perfectly. I am calling it in my program as follows.
    callable_stmt=con.prepareCall("{call pkg_name.proc_name()}");
    callable_stmt.execute();
    The problem is the control-of-flow is getting strucked in the second line I wrote. It is not giving any error also.
    Please clarify me what's wrong with my code?
    Seenu.

    And how long does the stored procedure take to run from your client machine when running it via sqlplus?

  • Call stored procedure(with parameters) via odbc

    In my application I like to use the below statement to call a stored procedure with parameter and return a result set.
    {CALL PP.getPerson('daniel')}
    but this will just return errors to my application.
    If I change the statement to:
    {CALL PP.getPerson(?')}
    and bind a parameter and its value, it will work.
    My question is, is it possible to call a stored procedure via ODBC without binding parameters in application? I mean, what will be my SQL equivalent if I don't want to do parameter binding in my application?
    Thanks in advance. I appreciate any help :-)

    hi 
    Please see the e.g bellow
    create proc proc_test(@SchoolNumber int,@SchoolName
    varchar(100),@StudentNumber int, @StudnentName
    varchar(100)output ,
    @StudentAddress varchar(100) output,
    @Studentbirthdate datetime output,
    @StudentPhoneNumber varchar(100) output,
    @GuardianName varchar(100) output)
    as
    begin
    select @StudnentName varchar=StudnentName ,
    @StudentAddress =StudentAddress,
    @Studentbirthdate =Studentbirthdate ,
    @StudentPhoneNumber =StudentPhoneNumber,
    @GuardianName =GuardianName
    from table where schoolno=@SchoolNumber
    and SchoolName=@SchoolName
    and StudentNumber=@StudentNumber
    return
    end
    http://technet.microsoft.com/en-us/library/ms187004(v=sql.105).aspx
    http://www.lynda.com/SQL-Server-tutorials/Using-input-output-parameters/104964/113058-4.html
    Please mark answered if I've answered your question and vote for it as helpful to help other user's find a solution quicker

  • 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

  • Java call stored procedure with nested table type parameter?

    Hi experts!
    I need to call stored procedure that contains nested table type parameter, but I don't know how to handle it.
    The following is my pl/sql code:
    create or replace package test_package as
    type row_abc is record(
    col1 varchar2(16),
    col2 varchar2(16),
    col3 varchar2(16 )
    type matrix_abc is table of row_abc index by binary_integer;
    PROCEDURE test_matrix(p_arg1 IN VARCHAR2,
    p_arg2 IN VARCHAR2,
    p_arg3 IN VARCHAR2,
    p_out OUT matrix_abc
    END test_package;
    create or replace package body test_package as
    PROCEDURE test_matrix(p_arg1 IN VARCHAR2,
    p_arg2 IN VARCHAR2,
    p_arg3 IN VARCHAR2,
    p_out OUT matrix_abc
    IS
    v_sn NUMBER(8):=0 ;
    BEGIN
    LOOP
    EXIT WHEN v_sn>5 ;
    v_sn := v_sn + 1;
    p_out(v_sn).col1 := 'col1_'||to_char(v_sn)|| p_arg1 ;
    p_out(v_sn).col2 := 'col2_'||to_char(v_sn)||p_arg2 ;
    p_out(v_sn).col3 := 'col3_'||to_char(v_sn)||p_arg3 ;
    END LOOP ;
    END ;
    END test_package ;
    My java code is following, it doesn't work:
    Class.forName ("oracle.jdbc.driver.OracleDriver");
    Connection con = DriverManager.getConnection
    ("jdbc:oracle:thin:@10.16.102.176:1540:dev", "scott", "tiger");
    con.setAutoCommit(false);
    CallableStatement ps = null;
    String sql = " begin test_package.test_matrix( ?, ? , ? , ? ); end ; ";
    ps = con.prepareCall(sql);
    ps.setString(1,"p1");
    ps.setString(2,"p2");
    ps.setString(3,"p3");
    ps.registerOutParameter(4,OracleTypes.CURSOR);
    ps.execute();
    ResultSet rset = (ResultSet) ps.getObject(1);
    error message :
    PLS-00306: wrong number or types of arguments in call to 'TEST_MATRIX'
    ORA-06550: line 1, column 8:
    PL/SQL: Statement ignored
    Regards
    Louis

    Louis,
    If I'm not mistaken, record types are not allowed. However, you can use object types instead. However, they must be database types. In other words, something like:
    create or replace type ROW_ABC as object (
    col1 varchar2(16),
    col2 varchar2(16),
    col3 varchar2(16 )
    create or replace type MATRIX_ABC as table of ROW_ABC
    /Then you can use the "ARRAY" and "STRUCT" (SQL) types in your java code. If I remember correctly, I recently answered a similar question either in this forum, or at JavaRanch -- but I'm too lazy to look for it now. Do a search for the terms "ARRAY" and "STRUCT".
    For your information, there are also code samples of how to do this on the OTN Web site.
    Good Luck,
    Avi.

  • Conversion of java Array to oracle SQL Array while calling Stored Procedure

    How java Array can be converted to oracle SQL array while calling Stored procedure with callable statement.
    i.e java Array ---> Sql Array in Oracle while setting the datatypes to callable statement arguments.

    Look at:
    http://forum.java.sun.com/thread.jsp?forum=48&thread=376735&tstart=0&trange=15
    Paul

  • SQLException Calling Stored Procedure

    Hello all,
    I'm getting the following exception when calling a stored procedure from Java. Maybe someone can help me out here. See details below.
    Exception
    java.sql.SQLException: ORA-01747: invalid user.table.column, table.column, or column specification
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
    at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
    at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
    at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
    at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
    at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)
    at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
    at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:656)
    at storedproctest.StoredProcApp.<init>(StoredProcApp.java:111)
    at storedproctest.DBApp.<init>(DBApp.java:20)
    at storedproctest.DBApp.main(DBApp.java:49)
    Database - Oracle 9.2.0.1.
    SQL> desc dsl_type;
    Name Null? Type
    SITE_NAME VARCHAR2(30)
    DSL_ID NUMBER(10)
    DSL_NAME VARCHAR2(20)
    THRESHOLD NUMBER
    AZIMUTH NUMBER
    SIG_DWN_COL_DURATION NUMBER
    COMMENTS VARCHAR2(100)
    CREATED_BY_ID NUMBER(5)
    DATE_CREATED DATE
    LAST_MODIFIED_BY_ID NUMBER(5)
    DATE_LAST_MODIFIED DATE
    DATE_DEACTIVATED DATE
    SQL>
    SQL> desc dsls;
    Name Null? Type
    SITE_NAME NOT NULL VARCHAR2(30)
    DSL_ID NOT NULL NUMBER(10)
    DSL_NAME NOT NULL VARCHAR2(20)
    THRESHOLD NOT NULL NUMBER
    AZIMUTH NOT NULL NUMBER
    SIG_DWN_COL_DURATION NOT NULL NUMBER
    COMMENTS NOT NULL VARCHAR2(100)
    CREATED_BY_ID NOT NULL NUMBER(5)
    DATE_CREATED NOT NULL DATE
    LAST_MODIFIED_BY_ID NOT NULL NUMBER(5)
    DATE_LAST_MODIFIED NOT NULL DATE
    DATE_DEACTIVATED DATE
    SQL>
    pl/SQL procedure
    PROCEDURE add( dslIn IN DSL_TYPE )
    AS
    dslId NUMBER := 0;
    BEGIN
    -- Do a little sanity checking
    utils.assert_non_zero( dslIn.created_by_id );
    utils.assert_not_null( dslIn.dsl_name );
    -- Get a new sequence value and insert the new dsl
    SELECT dsls_id_seq.NEXTVAL INTO dslId FROM dual;
    INSERT INTO dsls( SITE_NAME, DSL_ID, DSL_NAME, THRESHOLD, AZIMUTH, SIG_DWN_COL_DURATION, COMMENTS,
    CREATED_BY_ID, DATE_CREATED, LAST_MODIFIED_BY_ID, DATE_LAST_MODIFIED, DATE_DEACTIVATED )
    VALUES(( SELECT TRIM( global_name ) FROM global_name ), dslId, dslIn.dsl_name, dslIn.threshold,
    dslIn.azimuth, dslIn.sig_Dwn_Col_Duration, dslIn.comments, dslIn.created_by_id, SYSDATE,
    dslIn.created_by_id, SYSDATE, NULL );
    -- Commit this transaction to the database
    COMMIT;
    END add;
    Java code
    try {
    StructDescriptor dslStructDesc = StructDescriptor.createDescriptor( "DSL_TYPE", dbConn );
    Object[] dslAttributes = new Object[12];
    dslAttributes[0] = " "; // populated via pl/sql
    dslAttributes[1] = new BigDecimal( 0 ); // populated via pl/sql
    dslAttributes[2] = "Crator Lake";
    dslAttributes[3] = new BigDecimal( 098.34 );
    dslAttributes[4] = new BigDecimal( 23.67 );
    dslAttributes[5] = new BigDecimal( 101.1 );
    dslAttributes[6] = "Inserting from JAVA!";
    dslAttributes[7] = new BigDecimal( 2 );
    dslAttributes[8] = new java.sql.Date( GregorianCalendar.getInstance().getTimeInMillis());
    dslAttributes[9] = new BigDecimal( 2 );
    dslAttributes[10] = new java.sql.Date( GregorianCalendar.getInstance().getTimeInMillis());
    dslAttributes[11] = new java.sql.Date( GregorianCalendar.getInstance().getTimeInMillis());
    STRUCT dslType = new STRUCT( dslStructDesc, dbConn, dslAttributes );
    ocStmnt = (OracleCallableStatement)dbConn.prepareCall( "CALL DSL.add( ? )" );
    ocStmnt.setObject( 1, dslType );
    ocStmnt.execute();
    ocStmnt.close();
    dbConn.close();
    catch( SQLException sqlEx ) { sqlEx.printStackTrace(); }

    I'm not necessarily recommending the approach, but you can use a SELECT in the VALUES clause.
    It acts as a scalar subquery, so it will work in 8i and up in SQL, and 9i and up in PL/SQL.
    It will also work in PL/SQL in 8i if you use dynamic SQL.
    65765, use the code tags to format your code.
    I ran this in 9.2.0.4.
    INSERT INTO t
            id,
            value
    VALUES
            1,
            (SELECT ROWNUM FROM all_objects WHERE ROWNUM = 1)
    1 row created.
    SELECT * FROM t
            ID      VALUE
             1          1
    BEGIN
            INSERT INTO t
                    id,
                    value
            VALUES
                    2,
                    (SELECT ROWNUM FROM all_objects WHERE ROWNUM = 1)
    END;
    PL/SQL procedure successfully completed.
    SELECT * FROM t
            ID      VALUE
             1          1
             2          1

Maybe you are looking for