CF to MySQL stored proc question

looking at multiple examples of ColdFusion to MySql procedure
calls and I think code example 1 should return a value in the OUT
param. I get [empty string] displayed.
Code example 2 which changes the ColdFusion code by adding
<cfprocresult
name="searchResults">
and returning
<cfdump var="#searchResults#" label="Search Results">
works fine. I have about 10 examples including from Adobe
coded as example 1. Please would somebody explain :-)
TIA,
Mic

Well, when I use the Stored Procedures, I simply access the
cfprocresult's RecordCount to see if anything was returned. The
specifics (from example 2 that you had) is:
<cfif searchResults.RecordCount GT 0>
do the "yup he's a real guy"
<cfelse>
do your failure routine
</cfif>
You should get an error message, for instance, if you tried
to do a cfoutput on that variable, that you are trying to access a
complex data type (or something like that). So I would try to
access the RecordCount as 0 or not 0 if you are simply looking to
see if it found SOMETHING.
- Mike

Similar Messages

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

  • Interbase/Firebird stored proc questions

    I have several questions about Interbase/Firebird and the use of stored procedures with JDBC. I am using the FirebirdSQL driver but answers using other drivers (as noted) might be useful as well.
    1. Is there any way to call a stored procedure which returns a result set using CallableStatement? If so what does the jdbc string look like and what does the return part of the stored proc look like (presumably do-suspend.)
    2. Is there any way to call a stored procedure which returns a value using using CallableStatement? This would be where registerOutParameter() would be used. If so what does the jdbc string look like and what does the stored proc look like?
    3. Is there an 'identity' keyword? This would return the value of the last GEN_ID() call.
    4. I need to return a unique sequence from a stored proc. I am using the following syntax.
      for select tid from Telephone_Type
      where tid = :new_tid
      into new_tid
      do SUSPEND;Is there a simpler way to do this? The value is obviously already in new_tid, I just need some way to return it.

    For firebird 1.x or Interbase,
    There is no need to use a CallableStatement to call a
    stored procedure for
    a resultset.(doing that , you will get just one row
    only!)I know how to do it with a statement. That however was not the point.
    The only reason CallableStatement exists is to call stored procedures. And yet the driver, at the time I wrote this, did not work with CallableStatement.
    And in all the other drivers I have used CallableStatement is not limited to returning a single row. Perhaps you are thinking of a function. A function returns a type of value, but there are other ways of returning values. And some drivers actually allow for return values, result sets and output parameters all to be returned.

  • 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

  • MySQL Stored Procedures

    Title and summary says it all...
    I've read over and over that stored procedures are more
    robust, but I've yet to use one (Knowingly).
    So, if I have query such as
    insert into table (Name,Description) values ('Taco','Do not
    eat at Ma Bell');
    How would that be created/used?
    Also I was reading there are stored procedures for getting
    the next ID available, I forget its name offhand, but perhaps a
    procedure that does
    get next ID
    update that ID (with insert info above)?
    select * (return that record)

    Stored procs are great for performing complex database tasks
    but for simple table inserts, updates, etc. you won't see much
    benefit in using them over just straight SQL queries with cfquery.
    Check out the online reference for mySQL stored procs
    here.
    cheers

  • Stored Proc Migration question

    In sql server I have what is basically a select statement (multiple records) that is returned from a stored proc and as I understand it Oracle doesn't allow you do this in the same fashion.
    Instead a cursor has to be used (from what i understand?, although I am not 100% sure)
    so my question is this; Use of cursors in MS SQL Sever / Sybase can be resource intensive and slow. - my understanding of cursors in SQL server\ sybase is that you should really use them unless you have to.
    Is this the case in Oracle, or is it totally different?
    should I be looking at a different way of reproducing the data - i.e. using a procedure to create that data into a table then using a view to return the records.
    many thanks

    Any SQL statement that returns records is a cursor, whether in Oracle od SQL Server or Sybase. There may be a larger difference in SQL Server performance between explicit cursors (i.e. those formally declared) and implicit cursors (i.e. just select) than there is in Oracle, but they are all still cursors.
    The only way to retunr a result set to a calling program from a stored proc in Oracle is to use a cursor. Cursors, in themselves, are not any more resource intensive than the underlying sql statement. What tends to be resource intensive in Oracle is the row by row processing that people usually do with th cursors they fetch.
    In Oracle, you would generally do something like this to return a cursor to another program.
    PROCEDURE p (p_id IN NUMBER, p_cur OUT SYS_REFCURSOR)
    BEGIN
       OPEN p_cur FOR SELECT * FROM t WHERE id = p_id;
    END;Then call it like:
    DECLARE
       l_cur SYS_REFCURSOR;
       variables or a record to receive the fields
    BEGIN
       p(1, l_cur);
       LOOP
          FETCH l_cur INTO variables or record
          EXIT WHEN l_cur%NOTFOUND;
          <processing>
       END LOOP;
    END;The exact syntax to declare the cursor and call the stored proc will depend on the language of the calling program.
    You could also do P as a function returning a sys_refcursor.
    HTH
    John

  • Error committing transaction in Stored Proc call - prev solns not working

    Hi All,
    Our process invokes a DB adapter to fetch the response from the table for our request via Stored Procedure call but facing the below issue. Its a synchronous process. Stored Procedure is present inside the Package and we are calling the Stored procedure using that Package.
    What we did is created a DB datasource of XA type and tried to call the Stored Proc but it was giving a problem “ORA-24777: use of non-migratable database link not allowed” and hence according to this thread Using DB links in Stored proc call in DB adapter 11G SOA we have modified the datasource as non-XA type.
    While we do that, we could see that Stored Proc is called and the response is present in the reply payload inside the flow trace. But the instance is getting faulted and the error is “Error committing transaction:; nested exception is: javax.transaction.xa.XAException: JDBC driver does not support XA, hence cannot be a participant in two-phase commit. To force this participation, set the GlobalTransactionsProtocol attribute to LoggingLastResource (recommended) or EmulateTwoPhaseCommit for the Data Source.”
    We have tried the properties of global transaction support as one phase commit, emulate two phase commit and logging last resource but error remains the same.
    Database from which we are getting the response is of version "Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production". Will the database link error arises even if we connect to Oracle Database?
    Please could you advise me solutions to resolve this issue.
    Thanks in advance.

    You are using Non-XA because it means (among all others) that the commit issue can be handle by the DB as well.
    The Emulate Two Phase property imitating the XA transaction in that way, that it allows you to manage a local db transaction.
    You can stay with XA connection, but then you will have to use "AUTONOMOUS_TRANSACTION pragma" in your procedure.
    Enter the following link to find good explanation about all of your questions:
    http://docs.oracle.com/cd/E15523_01/integration.1111/e10231/adptr_db.htm#BGBIHCIJ
    Arik

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

  • Java Stored Proc and Oracle 8.0.6.20?

    Hi,
    I have a customer using Oracle 8.0.6 (on multi-platforms). We'll need to implement a pl/sql which needs to execute an external script.
    My understanding is there are only 2 ways to achieve this: (a) use Java stored procedure, (b) use C/C++ library
    Question 1: Is Java Stored Proc available in 8.0.6?
    Question 2: Is there anywhere I can download Oracle 8.0.6 (Windows, or Tru64, Linux)?
    - Will

    java in the database was introduced from Oracle8i onwards. this version of Oracle does not support java virtual machine in the database.
    You would need to use C/C++ external procedures.

  • Java stored proc from proxy Java classes generated from a web service?

    Hi gurus,
    I have searched "Java Stored Procedure" on this forum but could not find what I am looking for, so I have to post again.
    I need to use a web service and my client app is written in PowerBuilder 11 (Sybase), which claims that it will create a datawindow from a web service. Well, it turned out that PB can only handle simple stuff (it works with a very simple wsdl from the internet) but can't handle more complex ones that we need to use. So I am thinking about using Oracle JDeveloper(JDev) to create the web service proxy for the web service and then load it into Oracle as a Java stored procedure so that PowerBuilder can call the procedure. JDev succsfully generated the proxy and a few Java classes. My question is, do I need to load all the classes into the database? If yes, will the reference to the package work? For example, in a JDev generated class (the soap client class), it has package MyJdev.proxy; at the top. Or, will it work if I load all the classes included in package /MyJdev/proxy into the database?
    Thank you very much for any help.
    Ben

    For the java stored proc called from pl/sql, the example above that uses dynamic sql should word :
    CREATE OR REPLACE PACKAGE MyPackage AS
    TYPE Ref_Cursor_t IS REF CURSOR;
    FUNCTION get_good_ids RETURN VARCHAR2 ;
    FUNCTION get_plsql_table_A RETURN Ref_Cursor_t;
    END MyPackage;
    CREATE OR REPLACE PACKAGE BODY MyPackage AS
    FUNCTION get_good_ids RETURN VARCHAR2
    AS LANGUAGE JAVA
    NAME 'MyServer.getGoodIds() return java.lang.String';
    FUNCTION get_plsql_table_A RETURN Ref_Cursor_t
    IS table_cursor Ref_Cursor_t;
    good_ids VARCHAR2(100);
    BEGIN
    good_ids := get_good_ids();
    OPEN table_cursor FOR 'SELECT id, name FROM TableA WHERE id IN ( ' &#0124; &#0124; good_ids &#0124; &#0124; ')';
    RETURN table_cursor;
    END;
    END MyPackage;
    public class MyServer{
    public static String getGoodIds() throws SQLException {
    return "1, 3, 6 ";
    null

  • How to publish a Java Stored proc....

    Hi,
    I wrote the following Java code and loaded it into Oracle 8i, as Java stored procs.
    public class EmployeeStruct
    public int EmployeeNum;
    public String EmployeeName;
    public String Designation;
    and
    import java.sql.*;
    import java.io.*;
    import oracle.jdbc.driver.*;
    public class InsertData
    public static InsertEmployee(EmployeeStruct eps) throws SQLException
    Connection conn =
    DriverManager.getConnection("jdbc:default:connection:");
    String sql = "INSERT INTO EMPLOYEE_TABLE VALUES (?, ?, ?)";
    try
    PreparedStatement pstmt = conn.prepareStatement(sql);
    pstmt.setInt(1, eps.EmployeeNum);
    pstmt.setString(2, eps.EmployeeName);
    pstmt.setString(3, eps.Designation);
    pstmt.executeUpdate();
    pstmt.close();
    catch (SQLException e)
    System.out.println(e.getMessage());
    My question is how do I publish the InsertData proc. I tried :
    CREATE OR REPLACE PROCEDURE insert_data (e EMPLOYEESTRUCT) AS LANGUAGE JAVA
    NAME 'INSERTDATA(EmployeeStruct)';
    but this gives me PLS-00201, identifier EmployeeStruct must be declared.
    COULD SOMEONE HELP ME/ SHOW ME HOW ?
    I wish to call the java stored proc from an external java program.
    rgds
    Jeevan S
    null

    You can't pass Java classes to Java Stored Procedures via the PL/SQL wrapper. You'll have to write your wrapper to take the int as a NUMBER and the two Strings separately as VARCHAR2s, e.g.:
    CREATE OR REPLACE PROCEDURE insert_data
    EmployeeNum IN NUMBER,
    EmployeeName IN VARCHAR2,
    Designation IN VARCHAR2
    AS LANGUAGE JAVA
    NAME 'InsertData.InsertEmployee(int, java.lang.String, java.lang.String)';
    John H.
    null

  • Call EJB From Oracle Stored proc or Database loaded Java?

    Are there any examples of calling an EJB, residing in the OC4J on a machine separate from the DB server,
    from an Oracle PL/SQL stored proc.
    The Stored proc can call java loaded into the DB. That java makes the intial bean context. Or another way if suggested.
    The reason is that I need to use some drivers that I have so far been unable to load directly into the DB using
    loadjava util. I plan on using the driver in the EJB, located on a different machine. But I'd like so know if its possible to
    make the IntialContext call to the EJB container from PL/SQL. Are the OC4J drivers loadable to be
    able to be called from a database loaded java class? ( I might be a little off on my terminology)
    Bob
    [email protected]

    Hi Bob,
    Your question has been previously asked on this forum many times already.
    You can probably find the relevant postings by doing a search of the
    forum archives.
    To summarize those posts, as I understand it, the latest version of OC4J
    (version 9.0.3) contains a "oc4jclient.jar" file (I think that's the name
    of the file), that can be loaded into the Oracle database (using the
    "loadjava" utility), and which allows a java stored procedure to invoke
    methods on an EJB residing in OC4J.
    Please note that I have not tried any of the above -- I am only summarizing
    for you what has already been posted. And like I said before, a search
    of the forum archives will probably give you more details.
    Good Luck,
    Avi.

  • Should I do this with Java Code or Stored Procs ? (for best performance)

    Hi All,
    I need to decide where should I implement my business logic, in Java code or Stored procs.
    Here is the requirement :
    - One Order has 70 products (Order_Table )
    - Can be duplicate products, so I have to do summarize / grouping by product
    - For every product, I have to check, if it is entitled for a Bonus product, then I have to Insert one to Bonus_Table.
    - This is done when/after the transaction is SAVED (COMMIT)
    The question is, which one has better PERFORMANCE :
    (1) Create a rowsetIterator on the Order details (70 products) and call a stored procedure to do the logic for every single product (so that the Insert to Bonus_Table done in stored proc). means the stored proc will be called 70 times.
    OR
    (2) After the transaction is COMMITted, call the stored procs ONCE to do the logic for all the products at once.
    OR
    (3) I do all the logic with Java Code within ADF
    Given the requirement above, which approach is most efficient / best performance ?
    Thank you very much,
    xtanto

    Problem with this is that you ask 100 people and you probably get 100 different answers. ;o)
    Many would say that you push as much business logic into the database with your data; others might say you only put data in your database and your business logic is kept on the application server.
    In reality your would probably have a mix of both and your decision would probably be influenced by your own background ...
    Can't be more precise than that.
    Grant

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

  • 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

Maybe you are looking for