Failing to execute Sybase Stored Proc on startup

          This problem has been encountered while upgrading from weblogic 5.1 to 8.1: when
          a connection is used in a connection pool with the attribute conn.setAutoCommit(true),
          we get an error message:
          <<Cannot set auto commit to "true" when in distributed transaction.>>.
          When forcing setAutoCommit(false), then a new message appears about being unable
          to chain stored procedures. Obviously the transaction syncronization the entitry
          bean and the Sybase jConnect 5.5 jdbc driver is off. We had a similar problem
          long ago when installing weblogic 5.1 and fixed it with a subtle change in the
          weblogic.properties.
          What should be changed in the configuration? Or is this a deeper issue with the
          Jdbc driver or
          Sybase configuration?
          Particulars: weblogic 8.1 SP1 running on windows 2000 SP3; Sybase jConnect 5.5:
          jconn2.jar
          

Show me the whole SQLException stacktrace (in both cases).
          The issue is probably in the DBMS stored procedure itself,
          not the driver or weblogic. An odd fact is that Sybase stored
          procedures have a default execution mode, which the DBMS
          enforces. If the procedure was created when the connection
          was in the typical chained-off (autoCommit(true)) mode, the
          procedure will only be allowed to run when the connection is in
          that unchained autoCommit(true) mode. Alternately, if the
          procedure was created during an autoCommit(false) session, then
          the DBMS will only allow the procedure to run in that mode!
          However, Sybase will allow any procedure's executre-mode to
          be changed to allow it to run in any mode. The system stored
          procedure sp_procxmode will set that:
          sp_procxmode my_procedure_name, ANYMODE
          (something like that. Please check the documents).
          That should allow you to run without playing with the autoCommit mode,
          which you shouldn't anyway.
          Joe
          John Redden wrote:
          > This problem has been encountered while upgrading from weblogic 5.1 to 8.1: when
          > a connection is used in a connection pool with the attribute conn.setAutoCommit(true),
          >
          > we get an error message:
          >
          > <<Cannot set auto commit to "true" when in distributed transaction.>>.
          >
          > When forcing setAutoCommit(false), then a new message appears about being unable
          > to chain stored procedures. Obviously the transaction syncronization the entitry
          > bean and the Sybase jConnect 5.5 jdbc driver is off. We had a similar problem
          > long ago when installing weblogic 5.1 and fixed it with a subtle change in the
          > weblogic.properties.
          >
          > What should be changed in the configuration? Or is this a deeper issue with the
          > Jdbc driver or
          > Sybase configuration?
          >
          > Particulars: weblogic 8.1 SP1 running on windows 2000 SP3; Sybase jConnect 5.5:
          > jconn2.jar
          

Similar Messages

  • Sybase stored proc, no rows in the resultset

    Hi!
    I have a sybase stored proc that looks more like -
    IF OBJECT_ID('dbo.ETC_DETAILS') IS NOT NULL
    BEGIN
    DROP PROCEDURE dbo.ETC_DETAILS
    IF OBJECT_ID('dbo.ETC_DETAILS') IS NOT NULL
    PRINT '<<< FAILED DROPPING PROCEDURE dbo.ETC_DETAILS >>>'
    ELSE
    PRINT '<<< DROPPED PROCEDURE dbo.ETC_DETAILS >>>'
    END
    go
    CREATE PROCEDURE dbo.ETC_DETAILS
    @trade_id id,
    @broker_cd code,
    @contact_group_id int,
    @product_id id,
    @security_type_id smallint
    AS
    if(cond1)
    begin
         select distinct
    cd=t.cd,
    name=t.name,
    t.trade_id,..........
         from
         table1 t,
         table2 tt,
         table3 b,.......
         where t.trade_id = tt.trade_id
         and t.transaction_type_id = ttt.transaction_type_id
         and .....
    end
    else
    select distinct
    cd=t.cd,
    name=t.name,
    t.trade_id,..........
         from
         table4 t,
         table5 tt,
         table6 b,.......
         where t.trade_id = tt.trade_id
         and t.transaction_type_id = ttt.transaction_type_id
         and .....
    end
    go
    GRANT EXECUTE ON dbo.ETC_DETAILS TO public
    go
    IF OBJECT_ID('dbo.ETC_DETAILS') IS NOT NULL
    PRINT '<<< CREATED PROCEDURE dbo.ETC_DETAILS >>>'
    ELSE
    PRINT '<<< FAILED CREATING PROCEDURE dbo.ETC_DETAILS >>>'
    go
    EXEC sp_procxmode 'dbo.ETC_DETAILS','unchained'
    go
    GRANT EXECUTE ON dbo.dbo.ETC_DETAILS TO public
    go
    When run through SQL Editor - runs and returns me rows. But does not return any rows when invoked from Java. "gotResultSet" is true, but the while loop does not execute. Any clues, why? Here is the Java code.
    public class AllocationExtractor {
         public Collection getAllocations(int tradeId, String brokerCode, int contactGroupID, int productID, int securityTypeID) throws SQLException
              Connection c = null;
              String query = "{ call ETC_DETAILS(?,?,?,?,?) }";
              CallableStatement stmt = null;
              ResultSet rs = null;
              boolean gotResults = false;
              try{     
                   c = ConnectionFactory.getSybaseConnection(url, user, pwd);
                   stmt = c.prepareCall(query);
                   stmt.setInt(1, tradeId);
                   stmt.setString(2, brokerCode);
                   stmt.setInt(3, contactGroupID);
                   stmt.setInt(4, productID);
                   stmt.setInt(5, securityTypeID);
                   gotResults = stmt.execute();
                   if(gotResults)rs = (ResultSet) stmt.getResultSet();
                   if (rs != null){
                        System.out.println("Got resultSet");
                   while(rs.next()){
                        System.out.println("Iterating the resultset");
                        Allocation a = new Allocation();
                        a.setTradeID(rs.getString("trade_id"));
                        System.out.println(a.getTradeID());
                        allocations.add(a);
         public static void main(String args[]){
              AllocationExtractor e=new AllocationExtractor();
              Collection c = null;
              int tradeID = 3115;
              String broker_cd = new String("327");
              int product_id = 20;
              int contact_group_id = 1;
              int security_type_id = 1219;
              e.user = "developer";
              e.url = "jdbc:sybase:Tds:devbox:12344";
              e.pwd = "developer";
              try{
              c =     e.getAllocations(tradeID, broker_cd, product_id, contact_group_id, security_type_id);
              catch(SQLException se){
                   se.printStackTrace();

    Silly me! had switched the parameters to the method in Java.

  • Error executing DB2 stored proc

    Hi,
    We are trying to execute a Stored Proc in Mainframe DB2. We've prepared a PreparedStatement. The problem the stored proc works fine in some cases, but in some it fails even thouhg the data passed is same. Even the whole JVM crashes and there is no log in error.log file.
    Do you have any idea as to what might be the problem. We are using IBM WebSpehere5.0 and DB2v7.0
    Regards,
    Rohit

    For starters you should be using CallableStatement and not PreparedStatement.
    And if the VM goes down and no errors are thrown anywhere than it's time to talk to the vendor or consult the docs because that is beyond the scope of help you could be given here.

  • Getting error while invoking relational physical DS for sybase stored proc

    *com.bea.dsp.das.exception.DASException: com.bea.dsp.wrappers.rdb.exceptions.RDBWrapperException: {bea-err}RDBW0004: Error executing SQL query: [BEA][Sybase JDBC Driver][Sybase]SELECT INTO command not allowed within multi-statement transaction+.*
    I have created a physical DS function using "relational" in the wizard and connecting to sybase ASE stored procedure that is in unchained mode. I had configured the JDBC pool using BEA sybase non-XA 12.x driver.
    When i run the physical DS (or logical DS), i get the above error. The sybase srever(and stored proc) is hosted by an external system and right now i do not have access/contacts to change anything.
    After hours spent googling, it appears that the fix may possibly be setting "set chained off" before calling the stored proc. To achieve that, i tried the below two methods but nothing seems to work:
    - In the JDBC URL, set property via ?chained=off (also tried false instead of "off")
    - In Admin console/JDBC connection pool configuration/initSQL tried "SQL SET CHAINED OFF" and "SET CHAINED OFF"
    My ODSI version is 10gR3
    Oracle Workshop for WebLogic
    Version: 10.3
    Build id: 1137967
    I tried using java physical DS and get the same error. I wrote a test stored proc in my local PC sybase ASE and it runs fine. But i connected as "sa".
    I would like to exhaust all possible options from my side before making the long process of getting something changed in the external sybase DB like setting the proc mode to "anymode".
    Please help.
    Thank you.

    mikereiche wrote:
    Did the test stored proc use "SELECT INTO"?Yes. But it did not do much(code below)
    >
    Was the test stored proc tagged the same as the one that fails (chained/unchained?)Yes. "sp_procxmode" confirms that the test stored proc is in "unchained" transaction mode.
    >
    Can you get jdbc code that successfully calls the stored proc using the datasource?Yes, my colleague was trying the jdbc code and i was trying in the workshop with relational. She has left for the day so will post tomorrow. Please note that this is only for the test stored proc. The java jdbc also gets the same error for the "real" stored proc.
    >
    BTW - if you used "SET CHAINED OFF" as initSql, unless you have a table named SET, the sql will fail and the datasource will not be created. So that casts some doubt on whether the other setting "SQL SET CHAINED OFF" was applied.
    Also - the connections are reset to default when they are returned to the connection pool, so I think "SQL SET CHAINED OFF" should be used as the "Test Table Name" and Test On Reserve should be checked.Tried it now, but it does not work. I'm getting the same error.
    test stored proc:
    create procedure dbo.getCustomerMulti @cid_inp varchar(40)
    as
    begin
    select dbo.Customer.FirstName, dbo.Customer.cid, dbo.Customer.LastName, dbo.Customer.DateCreated, dbo.Customer.id into #temp from dbo.Customer
    select dbo.Customer.FirstName, dbo.Customer.cid, dbo.Customer.LastName, dbo.Customer.DateCreated, dbo.Customer.id from dbo.Customer where cid LIKE @cid_inp + '%'
    end
    Thank you.

  • Executing a stored proc from inside a stored proc

    Hi,
    I'm trying to execute a stored procedure from inside another stored procedure, and I can't seem to work out the correct syntax to use, could someone please give me a pointer, it's starting to drive me insane :]
    CREATE OR REPLACE PROCEDURE foo (blah in type) AS
    BEGIN
    EXEC OTHER_STORED_PROC();
    END;
    Thank you kindly,
    Anthony...

    EXEC is a SQL*Plus command, not PL/SQL syntax. In SQL*Plus, EXEC <<procedure name>> is just shorthand for
    BEGIN
      <<procedure name>>
    END;Calling a stored procedure from another stored procedure (or any PL/SQL block), can bypass the extra begin/end pair because it's already inside a PL/SQL block. Thus, the syntax you need is just
    CREATE OR REPLACE PROCEDURE foo (bar IN type)
    AS
    BEGIN
      other_stored_procedure();
    END;Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com/askDDBC

  • How to execute a stored proc with output params

    I have a SP that I created with 2 input varchar2s and 1 output varchar2. I developed it using PL/SQL Developer where it compiles and tests OK.
    When I try to run it using exec it fails with:
    exec validstate2('300', '5')
    BEGIN validstate2('300', '5'); END;
    ERROR at line 1:
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'VALIDSTATE2'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    If I try to add a set of quotes for an empty string for the output it fails as well.
    What do I need to do to get this to run? How do I handle that output parameter?
    Rick Price

    Here's the SP code, getcountry2 and get state are both functions that seem to work just fine.
    create or replace procedure ValidState2(mesgid IN varchar2, vcondition IN varchar2, valid OUT varchar2) is
    vvalid varchar2(20);
    v_temp varchar2(3);
    begin
    v_temp := getcountry2(mesgid, vcondition);
    IF v_temp = 'US' then
    vvalid := getstate(mesgid);
    valid := vvalid;
    else valid := 'Not US';
    end if;
    EXCEPTION
    when NO_DATA_FOUND THEN valid := 'No Data Found';
    end ValidState2;

  • Report fails on CE usin stored proc as data source and Native Client driver

    Iu2019m using Crystal Reports 10. I have a report with a stored procedure as data source. All my other reports using views as data source. Weu2019re upgrading db from SQL Server 2000 to 2008 and start using Native Client driver.
    Thereu2019s no problem to generate this report from .rpt on my local PC. But got the following error message when generate from Crystal Enterprise:
    Error Message: The table could not be found. File D:\Program Files\Crystal Decisions\Enterprise 10\Data\procSched\......reportjobserver\~tmp12c06c5641c4d50.rpt.
    It looks like sth related to Native Client driver. It works if I change to use old native driver in DSN on CE server.
    Any ideas/advises? Appreciated to your help!

    Hello,
    CR 10 does not support the MS SQL Native Driver, if you want to use OLE DB then use the MS OLE DB Provider for SQL Server up to SQL 2005. SQL 2008 does not support the MDAC version so you have to install the SQL 2008 Client tools to use the SQL Native 10 driver. CR 10 does not support that Native 10 Driver.
    See this MS Kbase: http://msdn.microsoft.com/en-us/library/ms131035.aspx
    Convert back to the old driver for 2005 and then use ODBC if using SQL 2008, it should work...
    Don

  • Fails to execute all statements in a stored procedure

    We are executing a stored proc on SQL Server 7.0. We are using the jdbc odbc bridge. The procedure has database inserts on seven tables.
    It executes fine when it's executed from the SQL server query analyzer. All the inserts go through without any problem.
    We have a problem when the proc is executed from the front-end. All the inserts except the last two go through without any problem. The sixth insert is partially completed (two out of 300 rows are inserted) and the seventh one is not at all executed.
    No error messages are generated. Surprisingly the stored proc executes fine when executed from the front-end from a Win 98 machine. It's giving a problem only on Win 2000. Could somebody please help us in finding a fix for this problem. Why is it behaving differently when executed from the front-end on a Win 2000 mahinne.
    Thanks in advance.

    Why is it behaving differently when executed from the front-end on a Win 2000 mahinne. Possible reasons.
    -Because you aren't sending the same data.
    -It is has an internal error and that is being ignored.
    -It isn't going to the same database and the stored proc is actually different.

  • Runtime exception java.lang.ClassNotFoundException on executing Stored Proc

    I am getting the below error when I try to execute a stored proc in Pointbase from weblogic.
    java.sql.SQLException: The external "DbLog::insLog" routine had the following runtime exception "java.lang.ClassNotFoundException: DbLog"
    import java.sql.*; import com.pointbase.jdbc.*; public class DbLog { static Connection conn = null; static Statement m_stmt; static Statement l_stmt; static CallableStatement m_callStmt = null; public boolean logPreAuth() { try { String I_URL = "jdbc:pointbase:server://localhost:9093/weblogic_eval"; conn = DriverManager.getConnection(I_URL, "PBSYSADMIN", "PBSYSADMIN"); /*String SQL_CREATE_PROC = "CREATE PROCEDURE insLog(IN P1 VARCHAR(30))" + " LANGUAGE JAVA" + " SPECIFIC insLog" + " DETERMINISTIC" + " NO SQL" + " EXTERNAL NAME \"DbLog::insLog\"" + " PARAMETER STYLE SQL"; m_stmt = conn.createStatement(); m_stmt.executeUpdate(SQL_CREATE_PROC); m_stmt.close(); */ Commented out because it throwed error saying, The routine "INSLOG" in schema "PBPUBLIC" already exists in system table SYSROUTINES. m_callStmt = conn.prepareCall("{ call insLog(?) }"); m_callStmt.setString(1, "Success!!"); m_callStmt.execute(); } catch (Exception e) { logger.error("Error in logPreAuth method" + e); } return true; } public static void insLog(String test) { try { l_stmt = conn.createStatement(); l_stmt.executeUpdate("Insert into logs values('" + test + "')"); l_stmt.close(); conn.close(); } catch (Exception e) { } }
    Please let me know how to solve this.

    I setted the classpath in commEnv.cmd as follows,
    set POINTBASE_HOME=%WL_HOME%\common\eval\pointbase
    set POINTBASE_CLIENT_CLASSPATH=%POINTBASE_HOME%\lib\pbclient57.jar
    set POINTBASE_CLASSPATH=%POINTBASE_HOME%\lib\pbembedded57.jar;%POINTBASE_CLIENT_CLASSPATH%;C:\bea\user_projects\workspaces\work1\utility\build\classes
    set POINTBASE_TOOLS=%POINTBASE_HOME%\lib\pbtools57.jar
    My DbLog class in the path, C:\bea\user_projects\workspaces\Work1\util\build\classes\net\local\util\common
    FYI, net\local\util\common is the package.
    But when I try to execute the page which calls RequestFilter.java, I am getting the following error,
    Error 500--Internal Server Error
    java.lang.NoClassDefFoundError: Could not initialize class net.local.util.common.DbLog
    Please find the code below,
    --RequestFilter.java
    import net.local.util.common.DbLog;  
    public final class RequestFilter {  
    public void log() {  
    DbLog dblog = new DbLog();  
    dblog.logPreAuth();  
    }  --DbLog.java
    package net.local.util.common;  
    import java.sql.*;  
    import org.apache.log4j.Logger;  
    import com.pointbase.jdbc.*;  
    public class DbLog {  
        private static final Logger logger = Logger.getLogger(DbLog.class);  
        private static boolean DEBUGGING = logger.isDebugEnabled();  
        private Connection conn = null;  
        private Statement m_stmt;  
        private Statement l_stmt;  
        private CallableStatement m_callStmt = null;  
        //static ResultSet l_rs = null;  
    public DbLog() {  
        logger.info("DbLog constructor called");  
        init();  
    public void init() {  
        logger.info("DbLog init called");  
    public void logPreAuth() {  
            try {  
                logger.info("Inside logPreAuth method");  
                String I_URL = "jdbc:pointbase:server://localhost:9093/weblogic_eval";  
                Class.forName("com.pointbase.jdbc.jdbcUniversalDriver").newInstance();  
                //Class.forName("com.pointbase.jdbc.jdbcDataSource");  
                conn = DriverManager.getConnection(I_URL, "PBPUBLIC", "PBPUBLIC");  
            String SQL_CREATE_PROC = "CREATE PROCEDURE insLog(IN P1 VARCHAR(30))" 
                    + " LANGUAGE JAVA" 
                    + " SPECIFIC insLog" 
                    + " DETERMINISTIC" 
                    + " NO SQL" 
                    + " EXTERNAL NAME \"DbLog::insLog\"" 
                    + " PARAMETER STYLE SQL";   
                m_stmt = conn.createStatement();  
                m_stmt.executeUpdate(SQL_CREATE_PROC);  
                m_stmt.close();    
                m_callStmt = conn.prepareCall("{ call PBPUBLIC.insLog(?) }");  
                m_callStmt.setString(1, "Success!!");  
                m_callStmt.execute();   
            catch (Exception e) {  
                logger.error("Error in logPreAuth method" + e);  
    public void insLog(String test)  
        try {  
            l_stmt = conn.createStatement();  
            l_stmt.execute("Insert into logs values('" + test + "')");  
            l_stmt.close();  
            conn.close();  
        catch (Exception e) {  

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

  • Problem while executing a Stored Procedure

    Hi,
    im a newbie,using Oracle 10g v(10.2.0.1.0) on linux machine.
    Im unable to execute following procedure through iSQLPLUS query interface.
    create or replace procedure pd_hr(
    pno varchar2,
    pdt date default sysdate,
    phr out number,
    perr_msg out varchar2
    ) as
    begin
         phr := 2;
    end pd_hr;
    VARIABLE phr number;
    VARIABLE perr_msg VARCHAR2(250);
    execute pd_hr('pno',NULL,phr,perr_msg);
    It flashes the following error when i try to execute the stored proc:
    ERROR at line 1:
    ORA-06550: line 1, column 44:
    PLS-00201: identifier 'PHR' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    I executed the following query through DBA login before executing the procedure:
    GRANT EXECUTE ANY PROCEDURE TO "SCOTT";
    Any kind of assistance will be priceless!
    Peter

    Hi, Peter,
    user10707566 wrote:
    Thanks Frank, it worked seamlessly!
    btw what the ':' signifies here?":" just means "this is a bind variable".
    It's convenient, because when you name a bind variable "phr", you can use ":phr" without worrying whether there is a column or a local variable that is also called phr, and, if so, which one takes precedence.

  • Executing a Stored Procedure with OUT Variables

    When you execute a stored proc withi OUT variables, do you have to add in the "Declare" section and "Begin/End" sections? Or can you just use "EXECUTE <stored proc>"??

    When you execute a stored proc withi OUT variables, do you have to add in the "Declare" section and "Begin/End" sections?
    Or can you just use "EXECUTE <stored proc>"?? You mean this?:
    michaels>  create or replace procedure p (o out varchar2)
    as
    begin
       o := 'Some out variable';
    end p;
    Procedure created.
    michaels>  var o varchar2(50)
    michaels>  exec p(:o)
    PL/SQL procedure successfully completed.
    michaels>  print o
    o                                                
    Some out variable                                

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

  • Handling result form Stored Proc in java program

    Folks, I have a question on how to handle results from Stored Procedures with the java.sql API. I execute a stored proc from a java program using the statement:
    statement.execute();
    where 'statement' is of type Statement. Then I get the results:
    ResultSet rs = query.getResultSet();
    The above returns me a ResultSet object. Now, my stored proc is such that it will return an integer in case of errors (as error code), and, if no error,it'll return the result set. Because I wouldn't know if the stored proc is returning an integer or a result set, how do I get the result of the stored proc in the java program? 'query.getResultSet()' would get me only an object of type ResultSet. What if the stored proc is returning an integer (i.e. when an error occurs)?
    Thanks.

    GSP wrote:
    Thanks to all for your replies. I do not have access to modify the stored procedure. I can just use it in my java program. The stored proc first validates its input parameters. If it finds them invalid, then it returns an appropriate error code (which is an integer) depending on which input param is found invalid. If all the input parameters are found valid, then it fetches the rows from the DB tables & returns them as result set. Now my question is: say if I give a statement as this in my java program:
    ResultSet rs = query.getResultSet();
    what if the stored proc returns an error code (Since the above statement gets only ResultSet object, how will it handle if the stored proc returns an int)? Is there any alternative?
    Ok, so there is a piece of missing data.
    Store procs, conceptuatlly can return data in a variety of ways.
    So the first step is to determine how the data is being returned.
    Unless you know that there is no way to determine how to use it in java.

  • Clearing Oracle Parameters to call diferent stored procs

    Sub Main
    Do While i < 3
    make_excel(i)
    i = i + 1
    Loop
    end Sub
    Sub make_excel(ByVal array As Integer)
    objCmd.Parameters.Add(New OracleParameter("p_cursor", OracleType.Cursor)).Direction = ParameterDirection.Output
    end Sub
    objCmd.Parameters.Clear()
    objCmd.Parameters.Remove("p_cursor")

    I agree with you. I was looking into mod_plsql, but it turns out that their development standards include not using Oracle HTTP server. The whole reason why they want to be able to execute a stored proc based on what is specified in an XML doc is that they want to avoid having to change their middle-tier configurations anytime a new stored proc or a change in stored proc parameters is made. I'm not familiar with what all is involved with .NET and the middle-tier, but supposedly this way, they can specify any stored procedure name and its parameters in an XML file. The XML is then suppose to be passed on to an Oracle stored procedure which will parse the XML and dynamically execute the stored procedure that was specified in the XML.
    Here is an example of the XML:
    '<Root>
      <PackageName>TEST_PKG</PackageName>
      <ProcedureName>TEST_PROC</ProcedureName>
        <Parameters> 
        <Parameter>
            <Name>EmpID</Name>
            <Value>12345</Value>
        </Parameter>
        <Parameter>
            <Name>Org</Name>
            <Value>ABC</Value>
        </Parameter>
        </Parameters>
    </Root>I basically need to parse out the pkg/proc names:
      SELECT t.COLUMN_VALUE.extract('//PackageName/text()').getstringval() PkgName,
             t.COLUMN_VALUE.extract('//ProcedureName/text()').getstringval() ProcName
         INTO v_pkg_name, v_proc_name
         FROM TABLE(xmlsequence(XMLTYPE(v_XML_input) .extract('/Root'))) t;...and then execute the procedure:
        EXECUTE IMMEDIATE 'BEGIN '||v_pkg_name||'.'||v_proc_name||'(:a, :b, :c); END;'
          using in v_in_param1, v_in_param2, out v_XML_output;The problem is that this approach is very complicated since there can be any number of IN/OUT parameters and of various datatypes. I would have to create all kinds of possible bind variables!

Maybe you are looking for

  • Serious about cleaning up my library, and i have this question on odd duplicate problem

    Hi all, I am serious about cleaning up my library, and i have this question: Is there such thing as a duplicate anymore in iTunes, and what happened to the View / Find duplicates feature? I could have sworn there was a built-in way... Anyway, In my m

  • All the messages are queued

    Hi, i find following error when i use exchange mail flow trouble shooter we have exchange 2010 sp1  5.7.1: The sender isn't authorized to send e-mail messages to this e-mail address. The possible reasons for this are: 1)The session isn't authenticate

  • Music library duplicate songs

    Anyone know why ios5 duplicates ALL my songs like 2-3 times in the music library> I have itouch 4g white

  • Summary column get less

    Hi, I have a formula column in group G1, which returns either 0 or 1, and there is summary column calculates the sum of this formula column on report level. it seems that the summary column doesn't count the first row which means I always get the sum

  • Wrong selection of number of processor in advanced boot option. system became dead slow.

    hello sir, i have acer aspire v3-571g laptop with windows 8.1 x64 based OS. Processor is Intel Core i5. To get a faster booting, i selected 2 processor instead of 1 in advanced boot option (msconfig) by mistake and now my laptop become dead slow on b