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.

Similar Messages

  • S'one tell me how to call Oracle Stored Proc from Java

    Hi,
    I have a problem in calling the Stored proc using callable statement.It looks like we are doing the same thing or no..
    Pl..let me know if you can correct me..Am enclosing the stored proc and java Code...
    CREATE OR REPLACE PROCEDURE StoreFTPAddress (FTP in FTPTYPE) is
    BEGIN
    INSERT INTO DES.FTPSERVICE(
    FTPID,
    COMPANYID,
    SERVERNAME,
    DIRECTORY,
    USERNAME,
    PASSWORD,
    INSTRUCTIONS)
    VALUES( FTPID.NEXTVAL,
    FTP.COMPANYID,
    FTP.SERVERNAME,
    FTP.DIRECTORY,
    FTP.USERNAME,
    FTP.PASSWORD,
    FTP.INSTRUCTIONS);
    END;
    JAVA CODE :;
    public String retrieveFormatExtension(String formatName)
    OracleResultSet rs_form = null;
    try
    conn = ConnectionDataObjectImpl.getConnection();
    Statement stmt = conn.createStatement();
    String sql_retrieve = "{call retrieveFormatExtension} " ;
    CallableStatement cst = conn.prepareCall(
    "{call retrieveFormatExtension(?,?)}");
    cst.setString(1," FName ");
    cst.registerOutParameter(1, OracleTypes.VARCHAR); // OUT Parameter
    cst.executeQuery();
    rs_form = (OracleResultSet) cst.getObject(1);
    cst.close();
    catch (SQLException ex)
    System.out.println("SQLException : " + ex.getMessage());
    return null;
    Regards
    Deepauk
    [email protected]
    null

    Syntactically it looks fine. Only thing is u r calling the proc with wrong name. Your procedure takes only one parameter and i.e
    IN type. I think u need to correct ur preparecall statement.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Ayappa:
    Hi,
    I have a problem in calling the Stored proc using callable statement.It looks like we are doing the same thing or no..
    Pl..let me know if you can correct me..Am enclosing the stored proc and java Code...
    CREATE OR REPLACE PROCEDURE StoreFTPAddress (FTP in FTPTYPE) is
    BEGIN
    INSERT INTO DES.FTPSERVICE(
    FTPID,
    COMPANYID,
    SERVERNAME,
    DIRECTORY,
    USERNAME,
    PASSWORD,
    INSTRUCTIONS)
    VALUES( FTPID.NEXTVAL,
    FTP.COMPANYID,
    FTP.SERVERNAME,
    FTP.DIRECTORY,
    FTP.USERNAME,
    FTP.PASSWORD,
    FTP.INSTRUCTIONS);
    END;
    JAVA CODE :;
    public String retrieveFormatExtension(String formatName)
    OracleResultSet rs_form = null;
    try
    conn = ConnectionDataObjectImpl.getConnection();
    Statement stmt = conn.createStatement();
    String sql_retrieve = "{call retrieveFormatExtension} " ;
    CallableStatement cst = conn.prepareCall(
    "{call retrieveFormatExtension(?,?)}");
    cst.setString(1," FName ");
    cst.registerOutParameter(1, OracleTypes.VARCHAR); // OUT Parameter
    cst.executeQuery();
    rs_form = (OracleResultSet) cst.getObject(1);
    cst.close();
    catch (SQLException ex)
    System.out.println("SQLException : " + ex.getMessage());
    return null;
    Regards
    Deepauk
    [email protected]
    <HR></BLOCKQUOTE>
    null

  • 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

  • Calling stored proc from java to return 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

  • How to fetch %ROWTYPE OUT param of  a stored procedure from Java program?

    I have a stored procedure that has IN / OUT parameter as table_name%ROWTYPE.
    From a java program how can I access this ROWTYPE variable?
    I tried all possible documentation and none of the explains whether or not this is supported.
    My use case expect exactly 1 record from the procedure and we would prefer not to use REF CURSOR.
    Is there a way to achieve this? If so, can someone help me with it by posting the sample code to achieve this?
    I tried all the possible OracleTypes to register the OutParameter and they all fail.
    Looks like there isn't any equivalent of %ROWTYPE in OracleTypes either.
    If you need, I can post my sample procedure that uses %ROWTYPE as OUT parameter.
    I really appreciate your help in this regard.
    - Karthik

    Hi,
    If "returning only 1 record" the showstopper for not using Ref Cursor, you might want to reconsider because as you probably know, the ref cursor is only a pointer and requires additional step to retrieve the data.
    Kuassi

  • Calling a COBOL stored proc from Java Servlet

    I am trying to call a COBOL stored proc from a Java Servlet. The stored proc is stored on a DB2 database. I need to send 6 inputs to the COBOL stored proc and the output will be the return code of the stored proc. I'm not sure if I'm going about this the right way. This is how my code looks...
    public int callStoredProc(CallableStatement cstmt,
    Connection con,
    String sYear,
    String sReportNbr,
    String sSystemCode,
    String sUserId,
    String sModuleNbr,
    String sFormId){
    int iParm1 = 0;
    try{
    Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
    catch(ClassNotFoundException ex){
    System.out.println("Failed to locate database driver: "
    + ex.toString());
    return iParm1;
    try{
    cstmt = con.prepareCall("{? = CALL MKTPZ90C
    cstmt.registerOutParameter(1, Types.INTEGER);
    cstmt.setString(2, sYear);
    cstmt.setString(3, sReportNbr);
    cstmt.setString(4, sSystemCode);
    cstmt.setString(5, sUserId);
    cstmt.setString(6, sModuleNbr);
    cstmt.setString(7, sFormId);
    cstmt.execute();
    iParm1 = cstmt.getInt(1);
    CloseSQLStatement(cstmt);
    catch(SQLException ex) {
    CloseSQLStatement(cstmt);
    System.out.println("SQL exception occurred:" +
    ex.toString());
    return iParm1;
    return iParm1;
    Could someone tell me if this is the right way to go about doing this?
    Thanks!!!!!!

    I didn't see the code where you create the database connection (variable "con"). However, the answer to your question "Is this the right way...", for me, is "Anything that works is the right way." So try it. That's a first approximation, but once you have something that works you can start on improving it, if that becomes necessary.

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

  • Getting exception whil calling an oracle stored procedure from java program

    Dear All,
    I encounter this error in my application when I call only the stored procedure but the view is executing fine from the application and my environment is as follow:
    Java 1.4
    oracle 10g
    oracle jdbc driver:9.2.0.8.0
    websphere portal 6.0.0.1
    this error is occur from time to time randomly, when it happens, the only workaround is to restart the server..Does anyone have any idea about this error?
    Unable to execute stored Procedure in Method
    java.lang.NullPointerException
    at oracle.jdbc.driver.T4C8Oall.getNumRows(T4C8Oall.java(Compiled Code))
    at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:1140)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java(Compiled Code))
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java(Compiled Code))
    at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3606)
    at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:5267)
    at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.pmiExecute(WSJdbcPreparedStatement.java:632)
    at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.execute(WSJdbcPreparedStatement.java:427)
    And sometime I am getting this exception
    Unable to execute stored Procedure in Method
    java.lang.ArrayIndexOutOfBoundsException: 27787320
    at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java(Compiled Code))
    at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:1134)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java(Compiled Code))
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java(Compiled Code))
    at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3606)
    at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:5267)
    at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.pmiExecute(WSJdbcPreparedStatement.java:632)
    at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.execute(WSJdbcPreparedStatement.java:427)
    Thanks
    Jay

    spacetorrent escribi&oacute;:
    for (int x=0; x <result.size(); x++){
    System.out.println(result.get(x));
    I can't do this, because result object is a Map, and I need write the Key of the Value to obtain.
    So I can do:
    result.get("res");And I odtain a *$Proxy3* Object

  • Deploy java stored proc. publishes java class names without package name

    Hi to All,
    Using JDevStudio 10132 I've created a 'Loadjava and Java Stored Procedure' deployment profile for my project. I've added my static method to the deplyment profile, but it generates script without java packege name, only pure class name.
    For example it executes: ...
    CREATE OR REPLACE PROCEDURE Procedure1(p1 IN VARCHAR2) AUTHID CURRENT_USER AS LANGUAGE JAVA NAME 'CryptoHelper.Procedure1(java.lang.String)';
    instead of
    CREATE OR REPLACE PROCEDURE Procedure1(p1 IN VARCHAR2) AUTHID CURRENT_USER AS LANGUAGE JAVA NAME 'mypackege.xxx.yyy.CryptoHelper.Procedure1(java.lang.String)';
    The CryproHelper class is definitely in mypackage.xxx.yyy package and JDeveloper Application Navigator shows correctly it.
    Any ideas?
    thx fo answers

    Hi,
    I've just been doing this on 10133 and found exactly the same thing. It's an easy fix to edit the package body - but it's rather annoying to have to manually do something that should just work.
    Steve
    *Hand editing the .deploy file to add in the package name works.
    Message was edited by:
    spilgrim

  • Cannt execute stored proc of one schema in another schema from java app.

    I am posting my problem in this forum as i i though it could be server-independent.
    I am working on apache tomcat and spring framework with Oracle db (schema/user A)
    We access oracle db from our java application by setting jndi and works fine.We have sqlstatements, stored procs and functions all run fine.
    Now we create a role (DBROLE) with all permissions to that original db schema/user(A) . We created another empty schema B and assigned that role(DBROLE) to that user B.
    (We grant all kind of permissions on tables/packages of schema A to user role DBROLE and also created synonyms)
    Intentions are: to access the schema A though schema B from application and avoiding direct access.
    In our spring application, we replaced database-settings with schema B.
    Things work fine: When its plain SQL statement is run from Java code but Stored proc wont run and we get
    'Wrong num of arguments/data types' error.
    Also all stored procs are in packages.To execute stored proc in java code, we use SimpleJdbcCall.
    I also checked run stored proc from schema B and its works. Only from web app, it doesnt work.
    Please suggest,what should be done to make this working or if there is other alternative.
    Thanks

    Instead of importing a scema in another schema specifiy the schemas in the external-schemaLocation property.
    SAXParser saxParser = new SAXParser();
    saxParser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", "xmlschema1.xsd, xmlschema2.xsd");

  • Type conversion when calling a java program in form 6i

    Hi,
    I would like to call a java program in form 6i. The java program takes a date parameter in. When I call the java program in form, how can I pass a date parameter to it?
    -- Method: isSystemDate (Ljava/util/Date;)Ljava/lang/String;
    FUNCTION isSystemDate(
    obj ORA_JAVA.JOBJECT,
    a0 ORA_JAVA.JOBJECT) RETURN VARCHAR2;
    Thanks.

    hi Tony,
    Perhaps you could notice that i myself commented in the beginning itself that I know that XE does not support JAVA. I wanted to know if there is any other way of calling java program from apex, perhaps from javascript,etc.
    if you RE READ the comment from Munky , he says that I could use PL/SQL for my objective and I have answered WHY it does not satisfy my problem
    thanks
    Edited by: eric clapton on Nov 14, 2010 9:11 AM

  • Perl and stored proc question

    Hello,
    I have used ASP w/ many SQL Server stored procs before and many Oracle stored procs with Java before, but I have yet to embark on calling stored procs from Perl.
    My current insert has been like this:
    my $dbh = DBIConnect->connect;     
    my $query1;
    $query1 = "INSERT into DEFAULT_PROJECT (NAME, EMAIL, LOCATION,PHONE,MGRNAME,MGREMAIL,"
        ."PROJNAME,PROJ_LOC,SPON_DEPT,SPON_BUS,PROJ_TYPE)
    ."values (?,?,?,?,?,?,?,?,?,?,?);"But am looking to replicate an equivalent call to an SP. ok, I've created my multi-table insert in SQL Plus, in PL/SQL, and it's just fine, no errors.
    Now I need to make the call.
    I've seen a few different things, including the use of DBIx like
    DBIx::ProcedureCall qw(sysdate);
    I've also seen something like
      $csr =  $dbh->prepare(q{
        BEGIN
          DEFPROJ_FORM_INSERTION;
        END;
       $csr->execute;I'm a bit confused having tried to shake down the CPAN board for a while with little luck.
    Anyone out there know how that call might look or go, given the supplied parameters and stored proc. name?
    I'd assume I'd be assigning the parameterized values much like I am now.
    Can any Perl/Oracle users out there shed any light on this?
    Thanks!

    alright, so I could not get that to work, but just to validate the insert statement I tried to alter it from an SP to a normal dynamic insert SQL statement.
    I get an Oracle error citing
    errERROR: Could not execute SQL! Error: ORA-00911: invalid character (DBD ERROR: OCIStmtExecute)
    DBI ERROR: ORA-00911: invalid character (DBD ERROR: OCIStmtExecute),Maybe I'm overlooking something simple. Anyone see anything out of place that pertains to the SQL statement?
    I think I have input it in a rather manageable, and easy to read block below:
    INSERT ALL
    INTO DEFAULT_PROJECT_USER
    (DEFPROJ_ID,DEFPROJ_ID_LTR,NAME,EMAIL,LOCATION,PHONE,MGRNAME,MGREMAIL,PROJNAME,PROJ_LOC, SPON_DEPT,SPON_BUS,PROJ_TYPE,REG_LEGAL,NETCRED_LOSS, EXPENSE_REDUC_CKB, STRAT_GOALS,AUDIT_COMPL,REV_GEN,CACS,CUSTOMIT,CUST_IMPACT,CALL_MGT,CALL_TRACK,
    CITILINK,DESKTOP,DIALER,DRI,ENGINEER,IMAGING,IPDT,MAINFR,MISC_OTHER,MORTSERV,MORTWEB,NON_MORTSERV,ORIG_PLAT,QUAL_MAP,DATAWARE_REPTS,SERV_APP_VDR,SOUTHBEND,WEB_SVCG,PROBLEM_RESOLVE,EXIST_PROC,BUS_OBJECTIVE,
    PENDING_PROJ,IMPACT_AREAS,REGULATORY_COMPLY,COMPLY_DEADLINE,SUB_DATE,EXPENSE_REDUCTION_TEXT,PRIORITY_RATING,ADDL_COMMENTS,PROJ_TYPE_OTHER,OTHER_EXPL_IT)
    values (defproj_user_seq.nextval,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,to_date(?,'YYYY-MM-DD HH:MI:SS'),SYSDATE,?,?,?,?,?)
    INTO DEFAULT_PROJECT_PROJMGR
    (DEFPROJ_ID,PROJ_MGR,STATUS,IT_PROJ_TYPE,IT_PROJNUMBER,FUNC_SPECS,FUNC_SPECS_DT,FUNC_SPECS_APPR_DT,BRD_APPROVED,BRD_APPROVED_DT,UAT_STARTDT,UAT_ENDDT,TESTER,RELEASE_DT, TARGETED_RELEASE_DT,BENEFIT_AMT,BENEFIT_CMTS,IT_LEVEL,IT_HOURS,FTES_SAVED,NUM_FTES,PROJQUE1,PROJQUE2,ACTUALCBA)
    VALUES (defproj_user_seq.nextval,NULL, NULL, NULL, NULL,NULL, NULL, NULL, NULL,NULL, NULL, NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,NULL, NULL,NULL,NULL)
    INTO DEFAULT_PROJECT_QA
    (DEFPROJ_ID,TERM,DEFINITION,BUS_NEED,CUST_IMPACT,CONTACT_NAME,IMPACT,IMPACT_PROCESS,IMPACT_DESC,PROCESS_LOC,PROJ_SCHED,PROJ_JUSTIF,IMPL_DATE,PROJ_EXPL,
    PROJ_TYPE,PROJ_JUST_MIT,PROJ_OWNER,PROJ_DATE_STATUS)
    VALUES (defproj_user_seq.nextval,NULL, NULL, NULL, NULL,NULL, NULL, NULL, NULL,NULL, NULL, NULL, NULL, NULL,NULL, NULL,NULL,NULL)
    SELECT object_name AS DEFPROJ_ID_LTR FROM all_objects where rownum <= 1;what could be leading to an invalid character? The error doesn't show which line.
    Thanks, but NEVER MIND...I found it - it's stupid perl! As opposed to a good language (Java).
    It balks at the extra semicolon, unlike Java would.
    Oh, and why am I using Perl you ask? Other than the "yeah, good question response", it's a long story, but suffice to say they don't allow for our UNIX server to be used with Java, just Perl. : (
    I do use Java a good amount here, but sometimes we're bound to crap on another planet where it just isn't an option for the server on which we use Java!
    Maybe someday! : )
    Message was edited by:
    user515689

  • Best place in VOimpl java code to call a stored proc to populate results

    Hello all,
    Using JDev 11g, ADF BC and Trinidad.
    I am building an application that is primarily used for searching large amounts of data. We already have stored procedures on the database that perform the searches and dump the results into a holding table (together with a "search id"). I have easilly built a prototype of this application: my view object is simply "select a, b, c from results where search_id = :bv" - I have a service method in the AM that runs the stored procedure, obtains the search ID, binds it to the :bv in the VO and executes the VO's query - it's all working really nicely. Range paging is effective, the VO itself performs well, and I am able to control how long the stored proc runs via setting a timeout value.
    Now, I'd like to generalize this. My thinking is this:
    1). I'll add a custom property to my VO that is the SQL statement needed to call the stored procedure.
    2). I'll add some bind variables to the VO to represent all the query parameters that can be passed to the stored proc. I'll also use custom properties to indicate these are "fake" bvs, and not in the SQL query itself.
    3). The VO's SQL will remain simply "select a, b, c from results where search_id = :bv"
    4). I will (have already tested) override bindParametersForCollection so that the "fake" bind variables aren't bound into the SQL.
    Now, the question: I want to override some method in the VO's java code to call the stored procedure. The stored proc needs to be called before the actual query for the VO is run, and also before the method getQueryHitCount is called (so that the count is correct). What is the method that would be the "best" place to do this? My current thinking is that I would put the call in an over-ridden executeQueryForCollection call. As far as my analysis has gone, it seems to be always called before getQueryHitCount, but I have no way of knowing if this is completely safe.
    Any thoughts from the BC experts out there?
    Best regards,
    John

    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.

  • Java stored proc

    hi i just now learnt how to write a
    simple java proc
    load java class
    publish
    call the function
    but how is this used by java people?
    for example.......
    i have a java class and inside it i have a method that accepts an input parameter.
    the input parameter is like below
    i have a table ... and a trigger on it when ever new insert/update takes place i have to pass the newly updated value for the column to the java program as the parameter so that they can process with that data
    how to achieve this
    any material that i can study for this ?
    raj

    this is what is written in the mail for me
    1. write java class with a method to call the refresh code. (cache)
    2. load this into oracle using loadjava as a oracle procedure.
    3. create a trigger after insert/update/delete on the table in question.
    4. call the java method in the trigger
    Java class--->
    HttpCallout.java (attached)
    Loading into Oracle as a procedure.--->
    loadjava -thin -verbose -user user/pass@DB HttpCallout.java
    create the trigger & call the java method--->
    JWCache.sql (attached)
    programs 1 thats attached to the file .............................................
    // Packages for http client library
    import HTTPClient.HTTPResponse;
    import HTTPClient.HTTPConnection;
    * This java stored procedure is attached as trigger to product_information
    * table. Any changes to the product_information table results in invocation of
    * this stored procedure which in turn call a JSP to invalidate the web object
    * cache that caches the product information
    public class HttpCallout {
    * This method establishes a http connection with the specified url
    public static void getURL( String hostname, String portnum, String url ) throws InterruptedException{
    try {
    // Process arguments
    String protocol = "http";
    String host = hostname;
    int port = Integer.parseInt(portnum);
    String page = url;
    // Grab HTTPConnection
    HTTPConnection con = new HTTPConnection( protocol, host, port);
    con.setTimeout(20000);
    con.setAllowUserInteraction(false);
    // Issue Get call
    HTTPResponse rsp = con.Get(page);
    // Terminate the connection
    con.stop();
    } catch( Throwable ex ) {
    ex.printStackTrace();
    another program tats atached to file
    Rem This SQL Script publishes the java stored procedure to the database
    Rem and creates a trigger for invoking the java stored procedure
    Rem
    CREATE OR REPLACE PROCEDURE getURL( p1 IN VARCHAR2,
    p2 IN VARCHAR2,
    p3 IN VARCHAR2) AS
    LANGUAGE JAVA NAME 'HttpCallout.getURL(java.lang.String, java.lang.String, java.lang.String)';
    CREATE OR REPLACE TRIGGER callout_trig AFTER INSERT OR DELETE OR UPDATE
    ON product_information
    BEGIN
    getURL('<server-host-name>:<port>','/jwcache/productinfo/JDBCInv.jsp');
    END;
    /

Maybe you are looking for

  • How to make multiple portals work in same domain (wlp 9.2)? IMPORTANT !!!

    We have domain where one portal application is in production now and other portal application have to deploy in the same domain. The first one is using global scoped DataSources and the new one is using application scoped because they have to use own

  • ALV doesn't go back

    Hi Experts, based on the SAP ALV example for "cl_salv_table" I wrote an ALV report. The first screen is for data selection. After this the ALV grid is displayed. The problem is that the standard back button doesn't work as expected. So after clicking

  • Installing photoshop 7.0

    I am having trouble installing my photoshop 7.0 on my new computer, it has windows 8 and 1.5 terra byte hard drive. When starting the program it gives a error message of the scratch disc is full than it shuts down.

  • Lion 10.7.4 -iphoto, safari and mail won't open

    I just bought four iMacs for my school. Two of them won't open the mail, iphoto or safari. I have spent quite a bit of time with the Apple rep, but at this point, he has run out of ideas. I have reinstalled Lion - not a clean install, but hate the th

  • Still no phone

    I'm still waiting to get help.  This is my second post here.  So far nothing is being done.  I'm really thinking of changing providers.  I'm the only one in the neighborhood without service and I am on oxygen.  Worst service I have ever had.