Multiple stored procs execution parallelly using single DBMS_SCHEDULER

Hi All,
I have to run 10 tasks - a few simultaneously, and a few periodically using DBMS_SCHEDULER.
But instead of creating 10 different Schedulers, is there a way in Oracle to create a single scheduler and invoke the tasks base on respective times?
I have been going thru SCHEDULERS documentation but i am unable to make much progress.
Thanks,
Chaitanya

Hi,
You can run the multiple process under the same scheduler to set the appropriate priority.
DBMS_SCHEDULER.create_job (
job_name => 'test_priority_job',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN DBMS_LOCK.sleep(10); END;',
start_date => SYSTIMESTAMP,
repeat_interval => 'freq=minutely;',
end_date => SYSTIMESTAMP + 1/48,
enabled => FALSE,
comments => 'Job used to test priorities.');
DBMS_SCHEDULER.set_attribute (
name => 'test_priority_job',
attribute => 'job_priority',
value => 1);
DBMS_SCHEDULER.set_attribute (
name => 'test_priority_job1',
attribute => 'job_priority',
value => 1);
Like the above code.
~Kushal

Similar Messages

  • Stored Proc running twice using DBMS_Scheduler

    Hello all,
    I have a vb front end that calls a main stored proc which submits scheduler jobs to execute several stored procs asynchronously. Everything is working, except the part that the several stored procs are running twice. In the troubleshooting, I have eliminated the front end from being the culprit and the stored procs themselves. Essentially, when I call the stored proc using dbms_scheduler.create_job, it runs twice, even manually. I am about at wits end trying to figure out why: Using Oracle 11gR2
    I started off setting up the programs
    begin
    --create program
    dbms_scheduler.create_program
    ( program_name => 'prog_name'
    ,program_type => 'STORED_PROCEDURE'
    ,program_action => 'usp_sub_proc_1'
    ,number_of_arguments => 8
    ,enabled => FALSE
    dbms_scheduler.DEFINE_PROGRAM_ARGUMENT
    ( program_name=> 'prog_name'
    ,argument_position=>1
    ,argument_name => 'name'
    ,argument_type=>'VARCHAR2'
    /*the remaining 7 arguments are in code but not display for space reasons*/
    dbms_scheduler.enable('prog_name');
    end;Then the main stored proc executes this code:
    declare v_job_name varchar2(100);
        v_1 varchar(50) := 'All';
        v_2 varchar(50) := 'All';
        v_3 varchar(50) := 'All';
        v_4 varchar(50) := 'All';
        v_5 varchar(50) := 'TEST';
        i_6 integer := 1;
        v_7 varchar(50) := 'TEST_NE';
        ts_8 timestamp := current_timestamp;
    begin
        v_job_name := 'uj_dmo_1';
    dbms_scheduler.create_job (v_job_name
                                            ,program_name => 'prog_name'
                                            ,job_class => 'UCLASS_1'
                                            ,auto_drop => TRUE
    --set parameters
    dbms_scheduler.set_job_argument_value(v_job_name,1, v_1);
    dbms_scheduler.set_job_argument_value(v_job_name,2, v_2);
    dbms_scheduler.set_job_argument_value(v_job_name,3, v_3);
    dbms_scheduler.set_job_argument_value(v_job_name,4, v_4);
    dbms_scheduler.set_job_argument_value(v_job_name,5, v_5);
    dbms_scheduler.set_job_argument_value(v_job_name,6, to_char(i_6));
    dbms_scheduler.set_job_argument_value(v_job_name,7, v_7);
    dbms_scheduler.set_job_argument_value(v_job_name ,8, to_char(ts_8));
    --enable job
    dbms_scheduler.enable(v_job_name);
    --execute job
    dbms_scheduler.run_job(job_name => v_job_name , use_current_session => FALSE);
    end;
    ...And this is where I get the double execution of the job, but I am just not seeing it in my syntax, dba_scheduler_jobs, logging, etc. Any help is greatly appreciated, thanks!!

    Well apparently I will not win any Captain Obvious awards;
    With 34MCA2K2's response with "what doesn't work" for some reason turned the light on. After some more testing here is what I found.
    This code works as expected :
    Exhibit A
    begin
    dbms_scheduler.create_job (job_name =>'TESTER'
                                   ,job_type => 'PLSQL_BLOCK'
                                   ,job_action => 'declare test1 integer := 1; begin test1 := test1 + 5; end;'
                                   ,auto_drop => True
       /*dbms_scheduler.enable('TESTER');   */
       dbms_scheduler.run_job(job_name => 'TESTER', use_current_session =>FALSE);   
    end;As does this:
    Exhibit B
    begin
    dbms_scheduler.create_job (job_name =>'TESTER'
                                   ,job_type => 'PLSQL_BLOCK'
                                   ,job_action => 'declare test1 integer := 1; begin test1 := test1 + 5; end;'
                                   ,auto_drop => True
       dbms_scheduler.enable('TESTER');  
      /*dbms_scheduler.run_job(job_name => 'TESTER', use_current_session =>FALSE);    */
    end;Exhibit A will create the job and is visible in the schedulerjobs view, and the RUN_JOB will execute it even when not enabled, but the pl/sql will not drop the job.
    Exhibit B will create the job and once enabled, executes the job and then drops from schedulerjobs view.
    Therefore, my desired results for running the jobs once asynchronously and dropping immediately is....
    begin
        v_job_name := 'uj_dmo_1';
    dbms_scheduler.create_job (v_job_name
                                            ,program_name => 'prog_name'
                                            ,job_class => 'UCLASS_1'
                                            ,auto_drop => TRUE
    --set parameters
    dbms_scheduler.set_job_argument_value(v_job_name,1, v_1);
    dbms_scheduler.set_job_argument_value(v_job_name,2, v_2);
    dbms_scheduler.set_job_argument_value(v_job_name,3, v_3);
    dbms_scheduler.set_job_argument_value(v_job_name,4, v_4);
    dbms_scheduler.set_job_argument_value(v_job_name,5, v_5);
    dbms_scheduler.set_job_argument_value(v_job_name,6, to_char(i_6));
    dbms_scheduler.set_job_argument_value(v_job_name,7, v_7);
    dbms_scheduler.set_job_argument_value(v_job_name ,8, to_char(ts_8));
    /*enable job*/
    dbms_scheduler.enable(v_job_name);
    /*execute job (Do not execute the code below, it will lead to multiple executions)
    dbms_scheduler.run_job(job_name => v_job_name , use_current_session => FALSE); */
    end;

  • Using Statement rather than CallableStatement for stored proc execution

    Cleary, if you need to extract output parameters from a stored procedure, then you must use a CallableStatement to execute it. However, if your stored procedure just returns a basic ResultSet, or performs a database update, is there any penalty to using a regular Statement to execute the stored procedure?
    For example -
    String sql = "exec testprocedure 'param1' 'param2'";
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery( sql );
    vs.
    CallableStatement cs = conn.prepareCall( "{call testprocedure(?,?)}" );
    cs.setString( 1, "param1" );
    cs.setString( 2, "param2" );
    ResultSet rs = cs.executeQuery();
    Any thoughts?

    Any thoughts?You would have to look at the actual driver code for a sure answer.
    But for any real database (which a stored proc suggests) I doubt there would be any difference at all. It would resolve to the same call.

  • JDBC receiver adapter with multiple stored procs error

    Hi all,
      I am doing a scenario IDOC-XI-JDBC. The destination system in MS SQL server 2000. I am passing variant config information to update the destination tables by triggering the same stored procedure multiple times with different parameters.
      Everything is correct, but JDBC adapter is giving me the following error
    Unable to execute statement for table or stored procedure. 'mk_EditAllowedLowerSpineImprintingOptions_proc' (Structure 'CallProc') due to java.lang.IllegalArgumentException
    My payload looks like this. This is just a partial payload, the blocks of CallProc continue till the CallsRemaining number reaches zero(0).
      <?xml version="1.0" encoding="UTF-8" ?>
    - <ns0:MT_UPDATEPERSONAVARIANTS xmlns:ns0="urn:sd:sales:sapvarianttablestopersona">
    - <CallProc>
    - <Update_Persona_Variants action="EXECUTE">
      <table>mk_EditAllowedLowerSpineImprintingOptions_proc</table>
      <AlbumType type="CHAR">7SPEC</AlbumType>
      <UpperSpineImprintingOption type="CHAR">UST</UpperSpineImprintingOption>
      <LowerSpineImprintingOption type="CHAR">NOL</LowerSpineImprintingOption>
      <EffectiveDate type="DATE">20040503</EffectiveDate>
      <CallsRemaining type="INTEGER">27</CallsRemaining>
      </Update_Persona_Variants>
      </CallProc>
    - <CallProc>
    - <Update_Persona_Variants action="EXECUTE">
      <table>mk_EditAllowedLowerSpineImprintingOptions_proc</table>
      <AlbumType type="CHAR">7SENT</AlbumType>
      <UpperSpineImprintingOption type="CHAR">UST</UpperSpineImprintingOption>
      <LowerSpineImprintingOption type="CHAR">LSP</LowerSpineImprintingOption>
      <EffectiveDate type="DATE">20040503</EffectiveDate>
      <CallsRemaining type="INTEGER">26</CallsRemaining>
      </Update_Persona_Variants>
      </CallProc>
    - <CallProc>
    - <Update_Persona_Variants action="EXECUTE">
      <table>mk_EditAllowedLowerSpineImprintingOptions_proc</table>
      <AlbumType type="CHAR">7SPEC</AlbumType>
      <UpperSpineImprintingOption type="CHAR">UST</UpperSpineImprintingOption>
      <LowerSpineImprintingOption type="CHAR">LSP</LowerSpineImprintingOption>
      <EffectiveDate type="DATE">20040503</EffectiveDate>
      <CallsRemaining type="INTEGER">25</CallsRemaining>
      </Update_Persona_Variants>
      </CallProc>
    ......CallProc blocks continue till CallRemaining reaches zero.
    I also tried making CallProc element appear just once in XML and repeating <Update_Persona_Variants> blocks like below
    <?xml version="1.0" encoding="UTF-8" ?>
    - <ns0:MT_UPDATEPERSONAVARIANTS xmlns:ns0="urn:sd:sales:sapvarianttablestopersona">
    - <CallProc>
    - <Update_Persona_Variants action="EXECUTE">
    </Update_Persona_Variants>
    <Update_Persona_Variants action="EXECUTE">
    </Update_Persona_Variants>
    </CallProc>
    </ns0:MT_UPDATEPERSONAVARIANTS >
    but still i get the same error.
    Can anyone guide me what is wrong.

    Well,
      The problem was with the way date was passed to the stored procedure, i just needed to format the date to yyyy-mm-dd and the error was solved. The error given by the JDBC adapter was not correct. I tried using logSQLStatement additional parameter, but for stored procedures it does not give out the actual SQL statement being fired. I was able to find the error in log files found on WAS server in transaction AL11.
       So i suggest to everyone having issues with JDBC adapter, please do not trust the error given in runtime workbench, always crosscheck in the logs in AL11 at the following location in your XI box
    DIR_INSTANCE\J2EE\CLUSTER\SERVER0\log. Here find date and time when you triggered your scenario and search for your table name or stored proc name, the java dump will give you a good information.
      I am giving points to everyone anyways.
    Thanks
    Pulin

  • Calling stored proc from java using ref cursor

    Hi All,
    We have a requirement to display all the records from a table on a JAVA screen. Due to some constraints, we have to write the query in the stored proc. We are trying to return a result set from the stored proc to the java code by using a ref cursor. Please refer to the code below.
    Following is the PL/SQL proc �
    procedure sp_user_course2(v1 OUT ref_cursor, persid in varchar2) as
    begin
    open v1 for
    SELECT lrn_exp_id, crs_name FROM emp_crs
    WHERE personid = persid;
    end;
    Here ref_cursor is of TYPE REF CURSOR declared in the package specification.
    The java code is �
    Callable stmt = conn.prepareCall("call sp_user_course2(?,?)");
    stmt.registerOutParameter(1,OracleTypes.CURSOR);
    stmt.setString(2,emplId);
    stmt.execute();
    OracleCallableStatement tstmt = (OracleCallableStatement) stmt;
    ResultSet rs = tstmt.getCursor (1);
    When I run the program, I get the following error (at stmt.execute()):
    [Oracle][ODBC][Ora]ORA-06553: PLS-306: wrong number or types of arguments in call to 'SP_USER_COURSE2' 6553
    Can anyone tell me what could be the problem with this code? I have read somewhere that REF CURSOR feature is available from Oracle 9i onwards. If so, then, is there any workaround for mapping REF CURSOR to Resultsets in Oracle 8i?

    These may help
    http://www.google.co.uk/search?q=jdbc+OracleTypes.CURSOR+tutorial

  • Report on results of multiple stored procs

    Post Author: RobotSlave
    CA Forum: Data Connectivity and SQL
    I'm creating a report where I have data coming from three different slightly related stored procs,  when I try to get sub totals from the result sets my data is all wacky. How to I get the totals right, here is a typical set of the recordsets:
    set 1:
    AMERICAN SECURITY PLUS 2 221 AUBURN/HERITAGE FORD Active 1 203.4100 Before Used Greater OtherAMERICAN SECURITY PLUS 2 221 AUBURN/HERITAGE FORD Active 1 146.1800 Before New Greater PreferredAMERICAN SECURITY PLUS 2 221 AUBURN/HERITAGE FORD Active 1 691.7800 Before Used Greater PreferredAMERICAN SECURITY PLUS 2 221 AUBURN/HERITAGE FORD Active 21 9718.3800 Since New Greater OtherAMERICAN SECURITY PLUS 2 221 AUBURN/HERITAGE FORD Active 1 196.5000 Since New Less OtherAMERICAN SECURITY PLUS 2 221 AUBURN/HERITAGE FORD Active 4 820.9000 Since Used Greater OtherAMERICAN SECURITY PLUS 2 221 AUBURN/HERITAGE FORD Active 22 7410.0500 Since New Greater PreferredAMERICAN SECURITY PLUS 2 221 AUBURN/HERITAGE FORD Active 6 2683.0500 Since New Less PreferredAMERICAN SECURITY PLUS 2 221 AUBURN/HERITAGE FORD Active 3 1533.6900 Since Used Greater Preferred
    set 2:
    AMERICAN SECURITY PLUS AUBURN/HERITAGE FORD 2 221 114 51 1998-08-03 13:13:00.000 Active New GreaterAMERICAN SECURITY PLUS AUBURN/HERITAGE FORD 2 221 114 5 1998-08-03 13:13:00.000 Active New LessAMERICAN SECURITY PLUS AUBURN/HERITAGE FORD 2 221 114 17 1998-08-03 13:13:00.000 Active Used Greater
    set 3:
    AMERICAN SECURITY PLUS 2 AUBURN/HERITAGE FORD 221 .0000 .0000 New GreaterAMERICAN SECURITY PLUS 2 AUBURN/HERITAGE FORD 221 .0000 .0000 New LessAMERICAN SECURITY PLUS 2 AUBURN/HERITAGE FORD 221 .0000 .0000 Used Greater

    Post Author: RobotSlave
    CA Forum: Data Connectivity and SQL
    I think I will just consolidate this data into one set in a stored proc.

  • Stored Proc Execution through OS command using shell script

    Hi All,
    I have a requirement of executing one stored procedure before putting data in Table through JDBC adaptor and two stored procedures after that.
    I was thinking to write a shell script and execute it before and after message processing in adaptor.
    Can anybody please tell me how should i write a shell script for it?
    I have identified that exec <Stored_Proc_Name> is the syntax for it.
    Will i need to write something more in this script?
    Thanks,
    Atul

    Hi Atul,
    Stored procedures are written on the Database server for which you are going to write JDBC adapter.
    you will just call the storedprocedure in to your adapter.
    as per your requirement you shd run one stored procedure (let us say SP1) and then you have to push data into tables and then run SP2 and SP3...
    so for this write three stored procedures and call them into another SP. in this SP you call SP1 first then insert statement to insert data into tables and then SP2 and SP3.
    finally call SP into your JDBC adapter.
    you can call SP1 in SP as below
    Var_SQL :='call SP1 (''' || Var_1 || ''',''' || Var_2 ||''')' ;
    EXECUTE IMMEDIATE Var_SQL;
    i think for this shell script is not required.. correct me if i am wrong...
    Regards,
    Sukarna.

  • Multiple files in different directory using single FILE adaptor

    Hi Guys,
    How can we handle multiple files having different format(PDF,TXT,EXCEL) and in different directory with the single FILE adaptor.
    I know by using "." we ca get mutilple files, but here tthe files are of different format and in different directory.
    Could you please explain as to how we can handle this scenarios?
    Thanks
    Sahil

    Hi,
    The short answer is - "No".
    The Long Question - "Why do you want to use a SINGLE channel".
    If your idea is to reuse the interface then dont worry... Except for the Senderchannel and Sender agreement all your other objects can be reused ...provided your sender apter converts the different files into the same XML format..
    For TXT you can use the simple file adpater..
    For excel see if you can use save the file as .CSV format...then you can use it directlky by the simple FIle adapter..
    For PDF use conversion agent... Here a blog to get u started on that ->
    /people/shabarish.vijayakumar/blog/2009/05/17/trouble-writing-out-a-pdf-in-xipi
    regards
    Arvind R

  • How to read multiple files of different name using single file adapter

    There are two inbound locations inbound1 and inbound2 , and the files structure present in these two inbound locations are same but the files start with different names example
    (1)files in inbound1 starts with file1,file2...
    (2)files in inbound2 starts with abc1,abc2...
    by using same file adapter with read option how can i read both files....

    Hi K.A.N.N.,
    You can define multiple directories using the above link in 11g and poll for the file as \*.*.
    Alternatively you can use the Synchronous Read and specify the file name at runtime.
    You can also use Pick activity to define multiple branches each with a File Adapter to read from a specified location with specified file name. Although it would contain multiple Adapter Definitions at Development-time, only one of the Adapters will execute at Run-Time.
    Regards,
    Neeraj Sehgal

  • Multiple Stored Procs in Receiver JDBC with transaction handling

    Hi All,
    We have a requirement to call  two Stored procedured in Receiver JDBC -- such that if any one of those procedure fails it should rollback the transaction/ or in other words commit only when both are successful.
    Is this handled in Receiver JDBC adapter?
    Thanks,
    Himadri

    Hello KK,
    Combining is not an option available for us.
    Our requirement is there are two SPs. --  SP1 and SP2. SP1 is mapped from the header segment and called only once. SP2 is from Item segment and called multiple times based on number of items. If anyone of those calls fails the transaction should be rolled back.
    Is it possible in the standard JDBC call in PI?
    Thanks and Regards,
    Himadri Chakraborty

  • Stored proc execution status, pls help

    hi,
    i need to know if there is a way to find out whether an sp has been executed successfully or not, with the status code being returned.
    i know about the dbms_output.getline() function but i don't know how to use it!
    pls help
    thank you

    Hi,
    do you mean something like that ?
    SQL> create or replace procedure getData(id in number)
      2  is
      3   status number;
      4  begin
      5   select count(1) into status from emp where empno = id;
      6   if status > 0 then
      7     dbms_output.put_line('Success');
      8   else
      9     dbms_output.put_line('Failed');
    10   end if;
    11  end;
    12  /
    &nbsp
    Procedure created.
    &nbsp
    SQL> set serveroutput on
    SQL> exec getData(1)
    Failed
    &nbsp
    PL/SQL procedure successfully completed.
    &nbsp
    SQL> exec getData(7369)
    Success
    &nbsp
    PL/SQL procedure successfully completed.
    &nbspRgds.

  • Use 'default' keyword in call string while calling stored proc?

    I am calling following sql server stored procedure from java code using my jdbc driver for sql server: CREATE PROCEDURE test_findTbInfo (
    @paramIn_Str varchar(10),
    @paramOut_Int int OUT,
    @paramIn_Int int = 20
    AS
    begin
    set @paramOut_Int = @paramIn_Int * 100
    end
    If I make a call like this:
    CallableStatement cs = conn.prepareCall(" { call test_findTbInfo(? , , ? ) }");
    cs.setString(1, "test_tab");
    cs.setInt(2, 4);
    cs.execute();
    It works without any error. But this is not a right behavior. !! The second parameter as you see is passed like an optional parameter. But in stored proc it is NOT an optional param and so if the value not passed it should fail...
    Now if I change the code to
    CallableStatement cs = conn.prepareCall(" { call test_findTbInfo(? , default, ? ) }");
    it works correctly. Gives error that "Procedure 'test_findTbInfo' expects parameter '@paramOut_Int', which was not supplied." which is correct.
    So is it a normal practice to use 'default' keyword while calling sql server stored procedures having optional parameters in jdbc ????
    Anyone knows ??? As far as I know "call test_findTbInfo(? , , ? )" works fine except in some cases and also it forces users to put all optional parameters at the end of parameter list in stored proc.
    Please let me know whether I should go with 'default' throuout for sql server stored proc while calling using my jdbc driver.
    Amit

    {?= call <procedure-name>[<arg1>,<arg2>, ...]}The question mark in the above is the result parameter
    that must be registered.
    That is not the same as an OUT argument.Yes that is true. The result value and OUT parameters are different but they both MUST be registered as per jdbc API
    "The type of all OUT parameters must be registered prior to executing the stored procedure; their values are retrieved after execution via the get methods provided here."
    Anyway, my original question still stays as it was. If there are some optional IN parameters in stored procedure
    e.g.
    PROCEDURE test_findTbInfo (
    @paramIn_Int int = 20,
    @paramOut_Int int OUT
    how do you call this?
    CallableStatement cs = conn.prepareCall(" { call test_findTbInfo( , ? ) }");
    cs.registerOutParameter(1, Types.INTEGER);
    cs.execute();
    or
    CallableStatement cs = conn.prepareCall(" { call test_findTbInfo(default, ? ) }");
    Also note that I am intending to use ONLY sql server driver for this.
    The first as well second seem to work. Except that second way is seems reliable. I just wanted a second opinion on that...
    Amit

  • Using Java within a stored proc to access multiple database connections

    Hi List;
    We have an environment where we have needs to provide cross database visibility between Oracle, Sql Server and PostgreSQL. So we need the capability for Oracle to query PostgreSQL and Sql Server tables, PostgreSQL must be able to query Oracle and Sql Server tables and Sql Server must be able to query Oracle and PostgreSQL tables.
    I'm thinking that we can implement stored procs which are either written in java or call a java process . The java code in turn should be able to connect to any DBMS desired via JDBC query the tables in question and return the result set to the calling database.
    Any thoughts on how feasable this is would be appreciated. Does this seem like a solid solution? Any initial concerns or red flags? what about performance via JDBC?
    Thanks in advance for your help.

    John,
    from your description I understand that you essentially program the VO yourself. So I suggest that you read chapter 35.9 of the 'Fusion Developer’s Guide for Oracle Application Development Framework' (I guess you know where to find it). Since you still call the actual SQL not all of the chapter apply, but you get the idea how it works.
    And yes you analyzed the behavior correct. executeQueryForCollection() is allways called bevore getQueryHitCount().
    Timo

  • Problem Obtaining multiple results from MySql Stored Proc via JDBC

    I've spent alot of time on this and I'd be really grateful for anyones help please!
    I have written a java class to execute a MySQL stored procedure that does an UPDATE and then a SELECT. I want to handle the resultset from the SELECT AND get a count of the number of rows updated by the UPDATE. Even though several rows get updated by the stored proc, getUpdateCount() returns zero.
    It's like following the UPDATE with a SELECT causes the updatecount info to be lost. I tried it in reverse: SELECT first and UPDATE last and it works properly. I can get the resultset and the updatecount.
    My Stored Procedure:
    delimiter $$ CREATE PROCEDURE multiRS( IN drugId int, IN drugPrice decimal(8,2) ) BEGIN UPDATE drugs SET DRUG_PRICE = drugPrice WHERE DRUG_ID > drugId; SELECT DRUG_ID, DRUG_NAME, DRUG_PRICE FROM Drugs where DRUG_ID > 7 ORDER BY DRUG_ID ASC; END $$
    In my program (below) callablestatement.execute() returns TRUE even though the first thing I do in my stored proc is an UPDATE not a SELECT. Is this at odds with the JDBC 2 API? Shouldn't it return false since the first "result" returned is NOT a resultset but an updatecount? Does JDBC return any resultsets first by default, even if INSERTS, UPDATES happened in the stored proc before the SELECTs??
    Excerpt of my Java Class:
    // Create CallableStatement CallableStatement cs = con.prepareCall("CALL multiRS(?,?)"); // Register input parameters ........ // Execute the Stored Proc boolean getResultSetNow = cs.execute(); int updateCount = -1; System.out.println("getResultSetNow: " +getResultSetNow); while (true) { if (getResultSetNow) { ResultSet rs = cs.getResultSet(); while (rs.next()) { // fully process result set before calling getMoreResults() again! System.out.println(rs.getInt("DRUG_ID") +", "+rs.getString("DRUG_NAME") +", "+rs.getBigDecimal("DRUG_PRICE")); } rs.close(); } else { updateCount = cs.getUpdateCount(); if (updateCount != -1) { // it's a valid update count System.out.println("Reporting an update count of " +updateCount); } } if ((!getResultSetNow) && (updateCount == -1)) break; // done with loop, finished all the returns getResultSetNow = cs.getMoreResults(); }
    The output of running the program at command line:
    getResultSetNow: true 28, Apple, 127.00 35, Orange, 127.00 36, Bananna, 127.00 37, Berry, 127.00 Reporting an update count of 0
    During my testing I have noticed:
    1. According to the Java documentation execute() returns true if the first result is a ResultSet object; false if the first result is an update count or there is no result. In my java class callablestatement.execute() will return TRUE if in the stored proc the UPDATE is done first and then the SELECT last or vica versa.
    2. My java class (above) is coded to loop through all results returned from the stored proc in succession. Running this class shows that any resultsets are returned first and then update counts last regardless of the order in which they appear in the stored proc. Maybe there is nothing unusual here, it may be that Java is designed to return any Resultsets first by default even if they didn't happen first in the stored procedure?
    3. In my stored procedure, if the UPDATE happens last then callablestatement.getUpdateCount() will return the correct number of updated rows.
    4. If the UPDATE is followed by a SELECT (see above) then callablestatement.getUpdateCount() will return ZERO even though rows were updated.
    5. I tested it with the stored proc doing SELECT - UPDATE - SELECT and again getUpdateCount() returns ZERO.
    6. I tested it with the stored proc doing SELECT - UPDATE - SELECT - UPDATE and this time getUpdateCount() returns the number rows updated by the last UPDATE and not the first.
    My Setup:
    Mac OS X 10.3.9
    Java 1.4.2
    mysql database 5.0.19
    mysql-connector 5.1.10 (connector/J)
    Maybe I have exposed a bug in JDBC?
    Thanks for your help.

    plica10 wrote:
    Jschell thank you for your response.
    I certainly don't mean to be rude but I often get taken that way. I like to state facts as I see them. I'd love to be proved wrong because then I would understand why my code doesn't work!
    Doesn't matter to me if you are rude or not. Rudeness actually makes it more entertaining for me so that is a plus. Nothing I have seen suggests rudeness.
    In response to your post:
    When a MySql stored procedure has multiple sql statements such as SELECT and UPDATE these statements each produce what the Java API documentation refers to as 'results'. A Java class can cycle through these 'results' using callableStatement dot getMoreResults(), getResultSet() and getUpdateCount() to retrieve the resultset object produced by Select queries and updateCount produced by Inserts, Deletes and Updates.
    As I read your question it seems to me that you have already proven that it does not in fact do that?
    You don't have to read this but in case you think I'm mistaken, there is more detail in the following website under the heading 'Using the Method execute':
    http://docsrv.sco.com/JDK_guide/jdbc/getstart/statement.doc.html#1000107
    Sounds reasonable. But does not your example code prove that this is not what happens for the database and driver that you are using?
    Myself I dont trust update counts at all since, in my experience some databases do not return them. And per other reports sometimes they don't return the correct value either.
    So there are two possibilities - your code is wrong or the driver/database does not do it. For me I would also question whether in the future the driver/database would continue to behave the same if you did find some special way to write your SQL so it does do it. And of course you would also need to insure that every proc that needed this would be written in this special way. Hopefully not too many of those.
    So this functionality is built into java but is not in common use amongst programmers. My java class did successfully execute a stored proc which Selected from and then finally Updated a table. My code displayed the contents of the Select query and told me how many rows were affected by the update.
    It isn't "built into java". It isn't built into jdbc either. If it works at all then the driver and by proxy the database are responsible for it. I suspect that you would be hard pressed to find anything in the JDBC spec that requires what that particular link claims. I believe it is difficult to find anything that suggests that update counts in any form are required.
    So you are left with hoping that a particular driver does do it.
    I suppose it is rare that you would want to do things this way. Returning rowcounts in OUT parameters would be easier but I want my code to be modular enough to cover the situation where a statement may return more than one ResultSet object, more than one update count, or a combination of ResultSet objects and update counts. The sql may need to be generated dynamically, its statements may be unknown at compile time. For instance a user might have a form that allows them to build their own queries...
    Any time I see statements like that it usually makes me a bit uncomfortable. If I am creating data layers I either use an existing framework or I generate the code. For the latter there is no generalization of the usage. Every single operation is laid out in its own code.
    And I have in fact created generalized frameworks in the past before. I won't do it again. Benefits of the other idioms during maintenance are too obvious.

  • Multiple proc. executions in VB with ADO

    Hi !
    I am migrating a VB application, from SYBASE to ORACLE. In this application, some stored proc. are called in a single "Execute" line of VB code:
    strSQL = "EXEC proc_name;EXEC proc_name;EXEC proc_name..."
    oCommand.Execute strSQL
    This works with SYBASE, not with ORACLE (an error is returned). How can I handle that? Do I need to decompose my orders in several single "Execute"??
    Thanks for your help!

    You can either decompose your stored procedure calls into a series of individual stored procedure calls or you can use an anonymous PL/SQL block to execute multiple stored procedures. Which way you go will depend on how interrelated the stored procedure calls are, whether you want individual calls to be atomic or whether you want a set of calls to be an atomic operation, etc.
    The anonymous PL/SQL block equivalent to your Sybase SQL statements would be-
    declare
    begin
      proc_name1;
      proc_name2;
      proc_name3;
    end;Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com/askDDBC

Maybe you are looking for

  • Sharing External Hard Drive with PC

    I have added external HD that has one partition formatted in FAT32 to my iMac. My goal is for this EX. HD to stay connected to my iMac but I want to be able to see it and share it with my PC. Both computers are located on my personal home network <ro

  • Unusual problem: crashes repeatedly in itunes after latest ?keyboard update

    Not wanting to divulge my sleep pattern too much( ), I go to sleep at night by leaving the computer on, unplugging it and turning on itunes and the visualiser and letting it play a song on repeat. The computer is in full screen mode and it used just

  • Lexicons

    Hi. I have a report query that begins with a select &report_sort, A.stu_name,... When I run the query in SQL+ passing in the report_sort parameter, it works. However, when I run my report from my form, the report data is not ordered according to the

  • Wrong time zone with rss feed in iWeb

    I'm using the RSS widget in iWeb, and all the RSS items are nine hours off - meaning they're on California time (I'm in Norway). The time zone is wrong even when I look at the feed in iWeb, so I don't think it's a server issue (and I'm not publishing

  • MergeClone in Toplink 10.1.3

    I have an object model with Booking and Status objects, where Booking has 1-1 relationship with Status. Since we're using Webservices, we try to perform update on the object returned by webservice with MergeClone as follows:           Session session