Re: ResultSet within ResultSet

From: Chris Smith (cdsmith_at_twu.net)
Date: 06/14/04

  • Next message: Vampyrotica: "HELP !!! java.sql.SQLException: General error HELP!!!!!"
    Date: Mon, 14 Jun 2004 08:55:36 -0600
    
    

    James wrote:
    > First of all I am wondering if this is reasonable?

    Well, it works, if that's what you're asking. You do need to be careful
    to use a different Statement for the inner query, since a new
    executeQuery on the outer statement would close the outer ResultSet.

    If you've got a potentially unlimited number of accounts for a customer,
    then you could of course run into problems trying to call them all into
    memory at once, but that's your call to make.

    Another alternative would be to run the query:

        select c.*, a.* from customers c, accounts a
            where c.cs_id = a.cust_id
            order by c.cs_id;

    Then your loop would look something like:

        int thisCustomerID = -1;
        Customer thisCustomer = null;

        while (next)
        {
            if (c.cs_id != thisCustomerID) thisCustomer = new customer;
            customer.addAccount(new account);
        }

    That's pseudocode, of course. The trade-off is that you have more total
    data coming over the wire, but fewer round-trips. That's likely to be a
    win, unless your customer records contain very large amounts of data.

    Incidentally, it's pretty much *never* a good idea to use *-style select
    in code. I'd definitely replace it with explicit field names, as soon
    as possible.

    > It might be better to
    > place such data intensive operations onto the server as PL/SQL but if
    > I did that how would I get my object model built up in the Java?

    You can't get PL/SQL to build Java objects for you on the client. You
    could, of course, encapsulate either of the original queries or the
    query I just write into a stored procedure, but this doesn't solve your
    problem.

    > I am using EJB so perhaps a CMR would be of some use here? Again
    > however I am not 100% sure how that would work.

    It's certainly not worth resorting to CMP over something like this.
    That would be extremely limiting on your use of the database, and the
    container couldn't really do a better job than you can in this instance.

    -- 
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.
    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
    

  • Next message: Vampyrotica: "HELP !!! java.sql.SQLException: General error HELP!!!!!"

    Relevant Pages

    • Re: Conversion of Business Objects to Flat Data Table and Viceversa
      ... I have PL/SQL query which returns all the fields. ... implementation for each business objects ... The problem is that for every child object in your heiarchy, ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: Weird performance issue ....
      ... If I understand - the problem is with a query returned from a stored proc ... "a query making a user function call" you mean something different again). ... as PL/SQL is assumed to be a "batch" environment. ... Not taking about power since where the issue is, the server ...
      (comp.databases.oracle.server)
    • signature based IDS/IPS effectiveness
      ... How effective are signature based IDS/IPS systems on text based ... protocols which involves grammar like PL/SQL. ... query patterns. ... So does not that mean stateless signature based IDS/IPS ...
      (Focus-IDS)
    • Re: Undocumented Matlab-Java connection
      ... Unfortunately, nobody replied to my query yet, so I went ahead and ... created a version of the findobj function that returns the relevant ... java objects. ... I'll be happy to hear feedback. ...
      (comp.soft-sys.matlab)
    • Re: HowTo: Trigger for Change- Logging
      ... the required privilege on v_$session. ... grant explicitly for PL/SQL. ... both cases and so I supposed that there is no lack on rights when I can query as user. ...
      (comp.databases.oracle.misc)