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.

Similar Messages

  • Having problems connecting getting results from MySQL

    Hi,
    I'm trying to learn some aspects of J2EE but i'm a bit
    stuck with EJB and i'm not sure what is going wrong so that's why i'm here :)
    What I want to do is very simple.
    I have a working MySQL database "musiccatalog" and I want to query it using any sort of client so to do that
    I create an Entreprise Application using netBeans 4.1
    Then I create a new CMP Bean called Album.
    I need something simple to test on so I have only one CMP Bean.
    My Album CMP Beans contains following CMP fields albumId, artistId, name, releaseDate, insertionTime.
    I also have a bunch of methods for LocalInterface: getters, setters, finders, and create() method.
    I don't need to add anything or write in the code cause it is generated by the IDE (netBeans 4.1)
    So my Album CMP Bean is written and I deploy project to see if all works fine. It works. My EJB-Module and Web-Module are deployed on the server (Sun Application Server 8).
    Next I create a new SessionBean called AlbumFacade that will access my CMP bean.
    I will have to add a lookupAlbumBean() method that will return a LocalHome interface, I also add a private variable of Type AlbumLocalHome. This variable is intialized in ejbCreate() method using the lookAlbumBean() method.
    Now it's time to add a business method to my SessionBean.
    I create a new buisness method public String getAlbumInfo()
    public String getAlbumInfo(int idAlbum) throws javax.ejb.FinderException {
    ejb.AlbumLocal albumL = albumLH.findByPrimaryKey(new Integer(idAlbum));
    return albumL.getAlbumName();
    so in this method i will get a reference to albumL interface and i will ask it to return the albumName of an album.
    So at this moment i'm done with Beans :)
    I redeply the app and it is redeplyed successfully.
    Now to test my beans i write a client. It'll be a servlet.
    What I need to do next is to create a ServiceLocator in my WebModule. This ServiceLocator will be used in the Servlet to lookup the remote interface of the AlbumFacade SessionBean.
    MyServlet will output a form with a textfield and a submit button where the user (me) types a number.
    If the servlet receives albumId parameter it'll look up the remote AlbumFacadeRemote interface and then i'll call the buisness logic of the SessionBean ( getAlbumInfo())
    and at this moment I should reach what I wanted but....
    The Application deploys and after I enter a number I got a vert nice StackTrace like this
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.transaction.TransactionRolledbackException: CORBA TRANSACTION_ROLLEDBACK 9998 Maybe; nested exception is:
         org.omg.CORBA.TRANSACTION_ROLLEDBACK: vmcid: 0x2000 minor code: 1806 completed: Maybe
         com.sun.corba.ee.impl.javax.rmi.CORBA.Util.mapSystemException(Util.java:207)
         com.sun.corba.ee.impl.javax.rmi.CORBA.Util.wrapException(Util.java:651)
         javax.rmi.CORBA.Util.wrapException(Util.java:279)
         com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:177)
         com.sun.corba.ee.impl.presentation.rmi.bcel.BCELStubBase.invoke(Unknown Source)
         ejb._AlbumFacadeRemote_DynamicStub.getAlbumInfo(_AlbumFacadeRemote_DynamicStub.java)
         web.AlbumServlet.processRequest(AlbumServlet.java:55)
         web.AlbumServlet.doPost(AlbumServlet.java:81)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:767)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
         sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         java.lang.reflect.Method.invoke(Method.java:585)
         org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:249)
         java.security.AccessController.doPrivileged(Native Method)
         javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
         org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:282)
         org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:165)
         java.security.AccessController.doPrivileged(Native Method)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
    note The full stack trace of the root cause is available in the Sun-Java-System/Application-Server logs.
    and it happens when the application queries the database.
    And unfortunately I don't see what may be wrong. If I do the same with a pointbasde sample database everything works fine.
    I tried to connect to MySQL via JConnector and also via jdbc:odbc bridge but i got still the same error.
    It drives me really mad 'coz I don't know what I do wrong.
    I can connect to database. But then something goes wrong.
    Can somebody give me an idea of what maybe wrong?
    Thanks :)

    Hail!!
    In fact, the problem IS in your PHP script.
    $senderEmail = $_POST['eMail'];
    $senderEmail = stripslashes($eMail);
    The last one should be:
    $senderEmail = stripslashes($senderEmail);
    PS:
    Next time, put your code inside formating tags...
    It will be easy for people to read your question and will improve the chances that someone answer it.

  • Retruring Multiple rows from a Stored Procedure

    The Oracle JDBC documentation shows how to return a cursor pointer through the parameter list of a stored procedure allowing a Java program to use the cursor like a normal result set. I've tried it (using the thin driver) and it works fine - however, I'm having trouble getting this to work running the program under a Weblogic server (using their own JDBC implementation). So, I have two questions:
    1) Has anyone had this problem before and solved it ??
    2) Are there any other techniques for getting multiple rows back from the database without having to fire "raw" sql at it ?

    Hi
    You could return not resultset but array, for example:
    PACKAGE TEST:
    type string_table is table of varchar2(80)
    index by binary_integer;
    function get_something (
    something1 out string_table,
    arraylength in number
    ) return number;
    PACKAGE'S BODY:
    function get_something (
    something1 out string_table,
    arraylength in number /** length of the array **/
    ) return number as
    cursor C is
    select something1, ...
    from test_table;
    pos number := 1;
    begin
    for position in C loop
    exit when (pos > arraylength);
    something1(pos) := position.something1;
    pos := pos + 1;
    end loop;
    return (pos - 1);
    end;
    Of course in this example you need to know length of your array
    (arraylength parameter), but you can avoid such problem, for
    example, by using DBMS_SQL package (or dynamic SQL feature in
    the Oracle8i).
    Andrew
    Mladen Gogala (guest) wrote:
    : Phil Hildebrand (guest) wrote:
    : : Is there a way that I can return multiple rows from a stored
    : : procedure for function ?
    : : Something like:
    : : CREATE FUNCTION sp_get_children (my_nip IN port.nip_num%
    TYPE)
    : : RETURN my_nip
    : : IS
    : : CURSOR child_cur IS
    : : SELECT nip_num
    : : FROM logical_port
    : : WHERE port_num = my_nip;
    : : child_rec child_cur%rowtype;
    : : BEGIN
    : : FOR child_rec IN child_cur
    : : LOOP
    : : RETURN my_nip;
    : : END LOOP;
    : : END tmp_sp_get_children;
    : : I know how to do it in Informix ( RETURN WITH RESUME ), but
    : I'm
    : : not running Informix ;)
    : : Thanks,
    : : Phil
    : In contrast with Informix, SQL Server and Sybase, Oracle
    : can not return a result set. the only workaround is to
    : return the cursor variable as such.
    null

  • Creating universe from MySql stored procedure?

    Hi,
    I am new to BusinessObjects. I need to create universes based on the schema in our MySql database. However, when I tried to create one from a stored procedure, I fount that I wasn't allowed to do that or the option to insert a stored procedure was grayed out.
    Is it true that universe creation from MySql stored procedures not supported, or is it just something I didn't do right? Is there any workaround?
    Thanks in advance!

    jason Lee,
    You cannot combine universes with table structures with that of the stored procedures.Thats the reason in the existing universe the option is greyed out to insert stored procedures. You need to create a new universe thru design wizard and check the option to "create a universe through the stored procedure" in the first page.
    Let me know your results
    Thanks,
    Karthik

  • Search has encountered a problem that prevents results from being returned. If the issue persists, please contact your administrator.

    Hello Guys,
    I am creating resultsource from central admin. If I create it from central admin it works fine. But if I am creating result source from power shell scripts it shows me following error message.
    An exception of type 'Microsoft.Office.Server.Search.Query.InternalQueryErrorException' occurred in Microsoft.Office.Server.Search.dll but was not handled in user code
    Additional information: Search has encountered a problem that prevents results from being returned.  If the issue persists, please contact your administrator.
    Any suggestion ?
    Thanks in Advance.

    Hi,
    Please provide more specific information about the issue. What type of content source you tried creating via powershell?
    Make sure you are using the approproate permission and search service application.
    Here is the reference for creating content resource via script:
    http://technet.microsoft.com/en-us/library/ff607867(v=office.15).aspx
    Regards,
    Rebecca Tu
    TechNet Community Support

  • How to SEND PAGE from Oracle stored proc

    I've searched all Oracle docs and internet. Need to be able to
    send a msg to a pager via SMS (or some other method) from a
    stored proc. Saw some mention of Oracle Paging Server but not
    much doc on implementing. Please feel free to post here or
    mailto:[email protected]

    if you need to send sms message you need to have wapgateway and
    wml background

  • Can't execute OS-level command from java stored proc

    I've written a couple simple java stored procs, the first of which writes an file and the second attempts a chown on it. I can write the file (which is written as the oracle user) just fine. I need to chown it, but can't. Here's the first proc:
    public static String writefile()
    String fileName = "/joetest/test.xml";
    try {
    File f = new File(fileName);
    FileOutputStream out = new FileOutputStream(f);
    PrintStream p = new PrintStream(out);
    p.println("this is only a test");
    p.close();
    return "create file successful!!!";
    } catch (Exception e) {
    return "Exception occurred writing file:"+e;
    Here's the proc I've been stuggling with:
    public static String chown(String inString)
    String[] command = {"/bin/sh", "-c", "/usr/bin/chown notjoe /joetest/test.xml"};
    if (inString != null) {
    command[2] = inString;
    try {
    Process p = Runtime.getRuntime().exec(command);
    return "Ownership change success!! "+p;
    } catch (Exception e) {
    return "Ownership change failure?? err="+e;
    The package is created with:
    CREATE OR REPLACE PACKAGE JOE.THISISATEST AS
    FUNCTION writefile
    return VARCHAR2
    AS
    LANGUAGE java
    NAME 'thisisatest.writefile() return java.lang.String';
    FUNCTION chown(Param1 VARCHAR2)
    return VARCHAR2
    AS
    LANGUAGE java
    NAME 'thisisatest.chown(java.lang.String) return java.lang.String';
    end;
    And I've granted the following privileges:
    begin
    dbms_java.grant_permission('JOE', 'java.io.FilePermission', '/joetest/test.xml', 'read, write, execute, delete');
    end;
    begin
    dbms_java.grant_permission('JOE', 'java.io.FilePermission', '/usr/bin/chown', 'execute');
    end;
    begin
    dbms_java.grant_permission('JOE', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
    end;
    begin
    dbms_java.grant_permission('JOE', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
    end;
    Here's the error that I'm getting:
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    Coincidentally, this is the same error that I used to get when I wrote the file without having been granted write privileges. Once I granted myself the proper 'write' permissions I could perform file IO just fine. Is there some runtime permission that I need to grant myself to run chown? I'm just guessing, as I can't find any permission like that in the java documentation. I have 'execute' permission on /usr/bin/chown and the oracle user can execute the command I'm attempting from the command line. ARRRRRGH.
    I am at my wits end with this. I've tried what seems like a thousand different syntaxes for the OS command and ran it from many different directories. Anyone have any thoughts at all as to why this is happening? I'm just clutching at straws now...

    Hmmmm. Granting 'execute' on '<<ALL FILES>>' to user JOE fixes this problem:
    begin
    dbms_java.grant_permission('JOE', 'java.io.FilePermission', '<<ALL FILES>>', 'execute');
    end;
    My security folks will not allow this when I port to production, but at least it is something.
    Message was edited by:
    user603023

  • Calling an EJB deployed in OC4J from Java Stored Proc in Oracle

    Hello!
    Trying to make a call to an EJB deployed in OCJ4 from a oracle java stored proc. After loaded orion.jar and crimson.jar lib into SCOTT schema, I can't get the JNDI Context working because of this error:
    ============================================
    javax.naming.NoInitialContextException: Cannot instantiate class:
    com.evermind.server.ApplicationClientInitialContextFactory. Root exception is
    java.lang.ClassNotFoundException:
    com/evermind/server/ApplicationClientInitialContextFactory
    at java.lang.Class.forName0(Class.java)
    at java.lang.Class.forName(Class.java)
    at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:45)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java)
    at javax.naming.InitialContext.init(InitialContext.java)
    at javax.naming.InitialContext.<init>(InitialContext.java)
    ===============================
    I did load the java with "loadjava" with on time with the "resolve" option and time time no option and still no working.
    Here is the EJB client code:
    =======================================
    import java.sql.*;
    import java.util.*;
    import javax.naming.*;
    import com.evermind.server.ApplicationClientInitialContextFactory;
    class EmpRemoteCall {
    public static void main(String[] args) {
    System.out.println(getEmpName());
    public static String getEmpName() {
    String ejbUrl = "java:comp/env/ejb/Emp";
    String username = "admin";
    String password = "admin";
    Hashtable environment = new Hashtable();
    environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.ApplicationClientInitialContextFactory");
    environment.put(Context.PROVIDER_URL, "ormi://127.0.0.1/testemp");
    environment.put(Context.SECURITY_PRINCIPAL, username);
    environment.put(Context.SECURITY_CREDENTIALS, password);
    //environment.put(Context.SECURITY_AUTHENTICATION, ServiceCtx.NON_SSL_LOGIN);
    //environment.put(javax.naming.Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
    com.kboum.sertir.essais.EmpHome homeInterface = null;
    try {
    Class.forName("com.evermind.server.ApplicationClientInitialContextFactory", true, ClassLoader.getSystemClassLoader());
    System.out.println("Creating an initial context");
    Context ic = new InitialContext(environment);
    System.out.println("Looking for the EJB published as 'java:comp/env/ejb/Emp'");
    homeInterface = (com.kboum.sertir.essais.EmpHome) ic.lookup(ejbUrl);
    catch (CommunicationException e) {
    System.out.println("Unable to connect: " + ejbUrl);
    e.printStackTrace();
    //System.exit(1);
    catch (NamingException e) {
    System.out.println("Exception occurred!");
    System.out.println("Cause: This may be an unknown URL, or some" +
    " classes required by the EJB are missing from your classpath.");
    System.out.println("Suggestion: Check the components of the URL," +
    " and make sure your project includes a library containing the" +
    " EJB .jar files generated by the deployment utility.");
    e.printStackTrace();
    //System.exit(1);
    catch (ClassNotFoundException e) {
    System.out.println("Unable to connect: " + ejbUrl);
    e.printStackTrace();
    //System.exit(1);
    try {
    System.out.println("Creating a new EJB instance");
    com.kboum.sertir.essais.Emp remoteInterface = homeInterface.findByPrimaryKey(Integer.valueOf("7369"));
    System.out.println(remoteInterface.getENAME());
    System.out.println(remoteInterface.getSAL());
    remoteInterface.setSAL(2);
    System.out.println(remoteInterface.getSAL());
    return remoteInterface.getENAME();
    catch (Exception e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
    return "error";
    null

    What I did to solve this problem was to
    create a simple RMI remote object that
    resides outside the database JVM and that
    serves as a proxy EJB client for your java
    stored procedure. The stored procedure can
    invoke a method on the remote RMI object
    which then looks up the EJBean's home
    interface and invokes the relevant method on
    the bean's remote interface, and relays any
    return values back to the java stored
    procedure.
    Hope this helps,
    Avi.
    null

  • Different ways to return results using a stored proc to calling application

    Hi, Can someone please suggest me different ways of returning results( set of rows and columns) from a stored procedure to calling application.
    Currently I am using sys_refcursor to return results to front end. Stored proc is executed fast, but cursor access and retrieval of results has some overhead.
    So can you suggest the ways which will be faster than this approach.
    Thanks.

    Currently the procedure executes quickly but the results from the ref cursor are returned slowly, this is because the query is slow, for whatever reason.
    Collecting in all the rows in the stored procedure first before returning them will
    a) Make the stored procedure slower taking the same amount of time to execute as current query takes to complete.
    b) Use more memory.
    c) Put more stress on the network as all rows will be transferred at once instead of using the arraysize/fetchsize to to fetch the rows in smaller packets.

  • Multiple Results from Table

    Hello,
    my EJB Query hast multiple Results.
    My Table:
    key | value
    01  | test1
    02  | test2
    My Selection:
    select Object(b) from PhoneBookEntityBean b
    What kind of result type must the finder method have and how can i handle it?
    Thanks for help and ideas,
    André

    Hi
    I'm having problem with my finder method also...
    I have a finder with name findByEmpName in which I pass string “empname” as parameter, for this I have put following in my ejb-jar.xml:
         <query>
              <query-method>
                   <method-name>findByEmpName</method-name>
                   <method-params>
                        <method-param>java.lang.String</method-param>
                   </method-params>
              </query-method>
              <ejb-ql>select object(b) from TestEntityBean b where b.empName like ?1</ejb-ql>
         </query>
    and inside persistent.xml
         <finder-descriptor>
              <method-name>findByEmpName</method-name>
              <method-params>
                   <method-param>java.lang.String</method-param>
              </method-params>
              <load-selected-objects/>
         </finder-descriptor>
    but when I use this finder method in my jsp, it return me null (no rows) but corresponding row is present in the database, findByPrimaryKey and create are working fine...
    Is any other setting need to be done?? pls help!!
    ~Raj

  • How to generate a report in pdf from a stored proc

    Hi, i need guidance on how to generate a report in pdf from an oracle stored proc.
    The environment is oracle 10gas + 10gdb.
    On a specific event, a PL/SQL stored procedure is called to do some processing and at the end of the processing to generate report which has to be sent to the printer (and optionally previewed by the user).
    Can anyone assist me with this?

    Hi ,
    One 'simple' way is by using the DBMS_SCHEDULER db package and the procedure CREATE_JOB(....) using as job_type the value 'EXECUTABLE'...
    Read for further info in 'PL/SQL Packages and Types Reference'.
    If you have access to OEM ... you can configure this there using wizard.....
    Other way is to use the External Procedure call capabiblity of Oracle DB Server...:
    http://www.oracle.com/pls/db102/ranked?word=external+procedure+call&remark=federated_search
    My greetings,
    Sim

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

  • Response from one stored proc. to another stored procedure call in JDBC

    Hi,
    I have to call 2 stored procedures, where the response from first stored procedure ( an id) is mapped as a parameter to the second stored procedure call.
    My question is that can this be achieved without using BPM?
    Can we somehow map the response from the stored procedure 1 to stored procedure 2 parameter w/o using BPM?
    I have to insert multiple rows using the stored procedure.
    Should I use STATEMENT unbounded times ( which means stored procedure is called multiple times) or should I use the parameter as unbounded ( like an array, maybe define the parameter as an array in the stored procedure)?
    From the performance standpoint, which approach is better?
    Please suggest.

    Hi Ardent !
    I think you could use 2 mapping programs (message mapping objects) in your interface mapping. The first one, executes and returns the ID to a message type defined by you for internal use only between both stored procedure executions. The second ones uses that message type as source message and the XML required by the JDBC for the second stored procedure execution as target message type. This can be done without BPM.
    Regards,
    Matias.

  • If the result from the stored procedure returns 0 rows I get this error returned:

    If the result from the following stored procedure returns 0
    rows I get this error returned:
    faultCode:Server.Processing faultString:'Variable transfers
    is undefined.' faultDetail:''
    How can I get round this?

    Well if I try this in a cfm page:
    <cfstoredproc procedure="GetTransfers"
    datasource="datasource" returncode="true">
    <cfprocparam type="in" cfsqltype="CF_SQL_VARCHAR"
    value="4">
    <cfprocparam type="in" cfsqltype="cf_sql_date"
    value="12/09/2006 08:42:00">
    <cfprocparam type="in" cfsqltype="cf_sql_date"
    value="12/09/2008 08:42:00">
    <cfprocresult name="transfers">
    I get an error like:
    [Macromedia][SQLServer JDBC Driver][SQLServer]Procedure or
    function 'GetTransfers' expects parameter '@fromdate', which was
    not supplied.
    But this procedure only accepts 3 parameters.

  • How to Call Stored Proc. through JDBC from SQL Server

    I have to call Stored Procedure by JDBC in java. This is the prog i m using:
    import java.sql.*;
    import java.io.*;
    class callSP
    public static void main(String a[]) throws Exception
    try
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection c=DriverManager.getConnection("jdbc:odbc:first","sa","");
    //CallableStatement cs=c.prepareCall("{? =call GET_CLUSTER(?)}");
    CallableStatement cs=c.prepareCall("{call GET_CLUSTER(?)}");
    cs.registerOutParameter(1,Types.CHAR);
    //cs.setString(1, "Teamwork");
    cs.execute();
    //cs.executeUpdate();
    String output=cs.getString(1);
    System.out.println(output);
    catch (SQLException e)
    System.out.println(e);
    This is the Stored Procedure:
    CREATE PROCEDURE GET_CLUSTER
    @Ip_THESAURUS_KEY_WORD CHAR(40)
    AS
    DECLARE @Lc_THESAURUS_CODE INT,
    @Lc_CLUSTER_CODE INT
    BEGIN
    --GET THE THESARUS CODE FOR THE KEYWORD
    SELECT @Lc_THESAURUS_CODE = THESAURUS_CODE
    FROM THESAURUS_LIST
    WHERE THESAURUS_KEY_WORD = @Ip_THESAURUS_KEY_WORD
    --GETTING THE CLUSTER ID
    SELECT @Lc_CLUSTER_CODE = CLUSTER_CODE
    FROM THESAURUS_ENRICH_CLUSTER
    WHERE THESAURUS_CODE = @Lc_THESAURUS_CODE
    --GET THE CLUSTER KEYWORDS
    SELECT THESAURUS_KEY_WORD
    FROM THESAURUS_LIST T,THESAURUS_ENRICH_CLUSTER C
    WHERE T.THESAURUS_CODE=C.THESAURUS_CODE
    AND C.CLUSTER_CODE=@Lc_CLUSTER_CODE AND NOT THESAURUS_KEY_WORD=@Ip_THESAURUS_KEY_WORD
    END
    GO
    Check it out what is problem. Data is not getting, it is giving exception.

    Please be specific regarding the problem that you are facing, that's the key to getting help in the forum. If there's exception in your program, such as NullPointerException or SQLException, please state it in your post.

Maybe you are looking for