Counting results in a ResultSet, discrepancies

This code was borrowed from another post on these forums:
rs.last();                 // Jump to last rowint
int count = rs.getRow());  // get the row count
rs.beforeFirst();          // reset to allow forward cursor processingNow... for a lot of queries, this seems to be working fine. Here's the odd part. We recently loaded a slightly larger amount of data onto the system, and started testing.
For a particular query, rs.getRow() returns 278, and I can iterate over the result using rs.next() to discover that there are actually only 156 rows. The odd thing is, I can change the query to sort the result in the opposite order, and rs.getRow() detects 156 correctly.
And if you thought that was odd, consider this: various similar queries with slightly different parameters return different numbers of results, and in every case but one so far (the one case was correct), the difference between the result from getRow() and iterating over the set has been exactly 122. :-)
So I thought it might be my code somewhere. I've scanned it fairly thoroughly and can't see any problems with the SQL or with the Java, aside from a worry that the database we're using (SAPdb) doesn't seem to like the particular join we use.
I'm not expecting any solutions, but more-so wondering if anyone else has ever seen unusual behaviour like this from SQL or JDBC.

Sure there is a problem with jdbc driver... it could be an error, it could be a not implemented function.
Each vendor implements the driver for the jdbc api and choose which methods will be abailable... methods that works over a driver didn�t have to work over another driver.
The best way of testing this differences is looking for which drivers are implemented on your vendor driver version... look for the methods implemented list at the vendor`s website, or decomplie the driver package ( if it is java implemented driver).
Sure you will be surprised

Similar Messages

  • Problem when Counting results of a query

    Hi all
    In our application, we use the Toplink Essentials Queryframework API to create queries because of JPA limitations.
    Now I have a problem: I want to count the results of a existing query, i.e. I have a ReportQuery and I want to count the results of it.
    I tried the following:
    ReportQuery query = ...
    ReportQuery countQuery = new ReportQuery(Pivot.class, builder);
    countQuery.addCount(COUNT,
    ExpressionBuilder.from("id", builder.subQuery(query)));
    countQuery.setShouldReturnSingleValue(true);
    return Integer.valueOf(session.executeQuery(countQuery).toString());
    Now it seems that Toplink executes the query but the result is not correct, i.e. the count result is NOT the same as the number of results in the original query.
    The subquery may contain group by's, a where clause and so on...
    Anyone has an idea how to count the number of results of another query in Toplink?
    It should have the same affect as a simple sql "select count(*) from (select ...)" query.
    Regards
    Michael

    Not exactly sure what your doing, what does the original ReportQuery select?
    You probably want to do something like the following:
    originalQuery...
    ReportQuery countQuery = new ReportQuery(Pivot.class, countBuilder);
    countQuery.addCount("id");
    countQuery.setSelectionCriteria(originalQuery.getSelectionCriteria());
    You may need to also call rebuildOn() if you reuse the same selection criteria from a different query.
    i.e.
    countQuery.setSelectionCriteria(originalQuery.getSelectionCriteria().rebuildOn(countBuilder));
    James : http://www.eclipselink.org

  • How to sum the count results?

    Hi,
    I have this query:
    SELECT SUM (cnt) FROM
    select max(timestamp), min(timestamp), count(1) as cnt from table1
    union
    select max(timestamp2), min(timestamp2), count(1) from table2
    It display sum of all count results. But how to display each result from query and sum result at the end?
    Best.

    OK, thanks, that helps a lot. Though if you could put {noformat}{noformat} before and after your code snippets that would help further.
    So you basically want a total at the end:WITH test_data AS (
    SELECT 1 col1, TO_DATE('16-AUG-08', 'DD-MON-YY') max_ts, TO_DATE('16-AUG-08', 'DD-MON-YY') min_ts, 1000 cnt FROM DUAL UNION ALL
    SELECT 1, TO_DATE('31-OCT-08', 'DD-MON-YY'), TO_DATE('31-OCT-08', 'DD-MON-YY'), 1000 FROM DUAL UNION ALL
    SELECT 1, TO_DATE('10-FEB-09', 'DD-MON-YY'), TO_DATE('01-JAN-01', 'DD-MON-YY'),422 FROM DUAL UNION ALL
    SELECT 1, TO_DATE('20-FEB-09', 'DD-MON-YY'), TO_DATE('20-FEB-09', 'DD-MON-YY'),1000 FROM DUAL UNION ALL
    SELECT 1, TO_DATE('20-FEB-09', 'DD-MON-YY'), TO_DATE('20-FEB-09', 'DD-MON-YY'),14825 FROM DUAL UNION ALL
    SELECT 1, TO_DATE('27-FEB-09', 'DD-MON-YY'), TO_DATE('27-FEB-09', 'DD-MON-YY'),1000 FROM DUAL UNION ALL
    SELECT 1, TO_DATE('28-FEB-09', 'DD-MON-YY'), TO_DATE('26-FEB-09', 'DD-MON-YY'),1000 FROM DUAL UNION ALL
    SELECT 1, TO_DATE('01-MAR-09', 'DD-MON-YY'), TO_DATE('01-MAR-09', 'DD-MON-YY'),1000 FROM DUAL UNION ALL
    SELECT 1, TO_DATE('05-MAR-09', 'DD-MON-YY'), TO_DATE('16-AUG-08', 'DD-MON-YY'), 5150 FROM DUAL UNION ALL
    SELECT 1, TO_DATE('27-APR-09', 'DD-MON-YY'), TO_DATE('30-OCT-08', 'DD-MON-YY'),8733 FROM DUAL UNION ALL
    SELECT 1, TO_DATE('27-APR-09', 'DD-MON-YY'), TO_DATE('20-FEB-09', 'DD-MON-YY'),10000 FROM DUAL)
    -- end test data
    SELECT col1, max_ts, min_ts, sum(cnt) total_cnt
    FROM test_data
    GROUP BY ROLLUP((col1, max_ts, min_ts));
    1 16-AUG-08 16-AUG-08 1000
    1 31-OCT-08 31-OCT-08 1000
    1 10-FEB-09 01-JAN-01 422
    1 20-FEB-09 20-FEB-09 15825
    1 27-FEB-09 27-FEB-09 1000
    1 28-FEB-09 26-FEB-09 1000
    1 01-MAR-09 01-MAR-09 1000
    1 05-MAR-09 16-AUG-08 5150
    1 27-APR-09 30-OCT-08 8733
    1 27-APR-09 20-FEB-09 10000
    45130
    11 rows selected.

  • WM: Enter Cycle Count Results (LI11N)- Time Stamp

    When cycle count results are entered, only the date of the count is recorded in table LINV. We are interested in capturing the time of entry as well for productivity related reporting.
    Is anybody aware of a solution that can accomplish this. For example populating a Z Table via user exit/BADI etc...

    Hello,
    You can do cycle counting with Rf transaction LM59 for the serialised material.
    1.My experience says when you have HUM activated then to track material HU & serialisation profile works together.
    2.You can do cycle counting of serailised & non serialsed material through Rf gun but clearance of this material will be issue. You may have to create one more transaction to clear the difference of  serialised materials like LI20
    Hope this input helps.
    Regards,
    Prashant

  • Count result

    Hello,
    I'm having trouble to understand how to display the count result from a row
    I want to list my categories with number of post:
    Music (3)
    Guitar (12)
    Drum (4)
    I have 2 table:
    Categories with 2 field -category_id and category_name
    Table post with several field like user id, name, title, etc
    I have a cat_id in this table who make reference to category_id
    set to InnoDB
    How to do this with Dreamweaver?

    >I'm having trouble to understand how to display the count result from a row
    A count result from a row?  Each row has a count of one, right? You might want to rephrase your question.
    >How to do this with Dreamweaver?
    This is not really a DW question, it's a SQL question:
    SELECT category_name, count(*) from
    post, categories
    where post.cat_id = category.category_id
    group by category.category_name

  • How to Input quickly year-end Stock Count Results

    Gurujee,
    Our company has 3 sites for inventory which is holdin  about 2,000 SKUs (Stock Keeping Units) value with 100 M Dollars. 
    Please educate me how to quickly input stock count results in matter of say 12 hrs - i.e. between december 31, 2009 and start new year January 1, 2010.
    How to do up and down adjustments QUICKLY within same categories, e.g. in Drinks up and down adjustments for items with similar values, but different flavors ?
    Rgds,
    Seifudin

    Ah, but I am unsure as to which part of my code goes where "..." is.
    Is it basically everything that I have put in the for loop?
    Right, I tried the following code:
    import java.util.Scanner;
    /* This program displays pass results for students */
    class StudentMarks
         public static void main (String[]args)
              Scanner input = new Scanner(System.in);
              int x, noOfStudents, mark;
              System.out.println ("Input number of students");     //outputs text
              noOfStudents = input.nextInt();
              while ((mark = input.nextInt()) != -1)
                  for (x = 1; x <=noOfStudents; x++) //loops no. of times of no. students
                             System.out.println ("Input exam mark for student");
                             mark = input.nextInt();
                             if (mark >= 40)
                                  System.out.println ("Pass");
                             else
                                  System.out.println ("Fail");
    }I don't know if this is the right way of going about it, but I am having a problem with it. When it asks me to input the number of students, I enter a number, but I have to enter it a second time for it to go to the next section, which is to ask for the mark. It then repeated the question of how many marks until I entered -1 to stop the program. So the number of students input is disregarded.
    So I can only assume I've put the wrong part of the code where "..." was? I really don't know where to go with this so if someone could just put on the right lines here, that would be great, thanks!

  • Counting Rows from a ResultSet

    Hi!
    If I retreive some information from a database, say by using:
    ResultSet RS = Stmt.executeQuery("select * from events");How can I get a value for the amount of rows in this ResultSet?
    Thanks!
    Alastair

    Almost everyone, when they first use ResultSet thinks of it as a container with the data rows already in there, and wonders why there's no size method.
    But that's not how they work. A ResultSet, generally, holds only one row at a time. next requests the next row from the database and before next is called the ResultSet doesn't know if another row is going to be available. Indeed the number of rows that qualify for return in the result set may actually change while you are processing it.
    Doing the SELECT COUNT(*) request asks the database for the number of rows that match any criteria in the SELECT, but that number may have changed when you actually retrieve the rows. Someone else may have added or removed rows.

  • SUM the COUNT RESULTS from 2 Tables

    If I have 2 seperate queries how can I sum the results of them
    select count(*) from tableA;
    select count(*) from tableB;
    MAXIMO@tarml > select count(*) from tableA;
      COUNT(*)
         500
    MAXIMO@tarml > select count(*) from tableB;
      COUNT(*)
         600
    MAXIMO@tarml > I want a query that gets me the 1100?
    I know people in here will know a simple solution that I can not find on the web?
    Thanks in advance again as always...
    Miller

    You should have read your given link more closely: You would have found
    select ( select count(*) from Table1 )
         + ( select count(*) from Table2 )
              as total_rows
      from my_one_row_table  --<---   replace with dual

  • URGENT: How to see the inserted row results in the ResultSet after an insertRow()?

    I want to see the inserted row in my result set immediately after I do an insertRow(). I don't want to do another select as my table has 100,000 records. I am using TYPE_SCROLL_SENSITIVE and CONCUR_UPDATABLE resultset with 8.1.7 thin driver.
    May be the driver does not support this because dbmd.ownInsertsAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)) always returns false. I just want to know is there a workaround or any solution for this problem. I would really appreciate if somebody could help me. Thanks in advance.

    Okay, first execute the query reqd. Then make whatever filters, navigational changes etc that are reqd. Once you are satisfied with the view of the data that you see on the screen, then from the Bex toolbar, click the Save button (Second from left) and choose the option Save as View Global. Give it a decsription and technical name.
    Hope this helps...

  • Counting rows in a ResultSet, help please?

    sorry there was a type error
    how to count the number of rows in a resultser object which may contains millions of rows? besides using a while loop? thanks

    You can do rs.last() then get the number of rows using rs.getRow() but as the previous poster hinted at this will take very long time with a lot of records as they all have to be retrieved before the rs.last() method can complete.

  • Count of group by resultset

    This may be very simple but I am unable to
    figure this out ...
    How do I get the count of
    a SQL query which has a GROUP BY clause
    and GROUP by functions.
    For example,
    How do I get the the numbers of rows fetched
    by the following query:
    select asse_no,
    SUM( round(gross_amt + srg + hbt )) as total_outs
    from pls_demand_1
    having SUM(round(gross_amt + srg + hbt )) >80000
    group by asse_no
    In SQL Plus, I see 38 rows fetched.
    BUT ...
    I will run this query in Oracle Reports.
    I need to get the count somehow ...
    Thanks in advance ...

    Try:
    select asse_no,
    SUM( round(gross_amt + srg + hbt )) as total_outs,
    count(asse_no)
    over (order by asse_no) the_record_number
    from pls_demand_1
    having SUM(round(gross_amt + srg + hbt )) >80000
    group by asse_no
    This does work ... but if you are running this in oracle reports why not just put a summary function against the query.

  • Best way to loop through multiple rows to search for a count result

    I have a script where I'm trying to find a Rollup row without any children. I have created a SQL statement to do this, but I can only input one point at a time. If the count is greater than 0 then i'm good to go. If the count is 0 then I want to know about it.
    select count (*) from (Select * From ESSBASE_FCS.Ham
    where hier_pt like (Select substr(hier_pt, 1,8)||'%' as hcy_pt
    From ESSBASE_FCS.Ham
    Where Hier_Pt = '412375....')
    And Cctr_Or_Rollup 'Rollup')
    What is the best way to develop a SQL script that searches through all my Hier_pt's and return everything with a count of 0, instead of manually inputing each hier_pt at a time?
    Thanks for any help.

    Hi,
    Please read SQL and PL/SQL FAQ
    Please provide table structure, sample data and expected output.
    Additionally when you put some code please enclose it between two lines starting with {noformat}{noformat}
    i.e.:
    {noformat}{noformat}
    SELECT ...
    {noformat}{noformat}
    I noticed also that you have posted the same question here: {message:id=10678000}
    If you move your question to another forum please mark the previous question as answered.
    Regards.
    Al
    Edited by: Alberto Faenza on Nov 7, 2012 5:03 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Count Result With Column

    Hello,
    Oracle 10.2.0.1
    OS : Windows XP
    All we have scott.emp. If is says :
    SQL> SELECT DEPTNO,COUNT(*) AS CNT FROM EMP GROUP BY DEPTNO ORDER BY 1;
        DEPTNO        CNT
            10          3
            20          5
            30          6My Requirement :
          COL1
    10       3
    20       5
    30       6Means count of deptno+count of rows should be concatenated in a single column, so that my user can know that dept no. 10 has 3 rows, dept 20 has 5 rows. For this i can have two columns, but if it is possible in a single column, then my datagrid can be fit in the current window (now user do'nt need to scroll).
    Thanks.

    Hi,
    user12050217 wrote:
    ... My Requirement :
    COL1
    10       3
    20       5
    30       6Means count of deptno+count of rows should be concatenated in a single column, so that my user can know that dept no. 10 has 3 rows, dept 20 has 5 rows. For this i can have two columns, but if it is possible in a single column, then my datagrid can be fit in the current window (now user do'nt need to scroll).Display is usually handled best by the front end. It's probably better to learn how to control your data grid, so that, for example, it doesn't allot 10 digits for deptno when you know it will always be 2 digits.
    If you must use a back-end solution, then use TO_CHAR to convert the NUMBERS to strings, and then use || to concatenate them:
    SELECT    TO_CHAR (deptno,    'FM99')    ||
           TO_CHAR (COUNT (*), '999999')          AS col1
    FROM       scott.emp
    GROUP BY  deptno
    ORDER BY  deptno
    ;

  • Me again! - printing count results

    hello,
    i made a post earlier about this and someone replied but i still couldn't get it to work. i have to create a game (paper scissors rock) and it has to keep count of the number of wins player 1 and 2 have. i have to use separate methods. the problem is for some reason when it prints the number of wins it comes up with 0. i have cut out any unneeded code. please please help:
    public class question2a
    public static void main(String[] args)
    char quit = 'y';
    char c1 = 0;
    char c2 = 0;
    int player1wins = 0;
    int player2wins = 0;
    do
    question2a.getinput();
    question2a.winnercalculation(c1, c2, player1wins, player2wins);
    System.out.println("Do you want to play again [y/n]");
    quit = SavitchIn.readChar();
    SavitchIn.read();
    } while (quit != 'n');
    question2a.outputresults(player1wins, player2wins);
    public static void getinput()
    char c1;
    char c2;
    int player1wins = 0;
    int player2wins = 0;
    System.out.println("Player 1 please enter a letter");
    c1 = SavitchIn.readChar();
    SavitchIn.read();
    System.out.println("Player 2 please enter a letter");
    c2 = SavitchIn.readChar();
    SavitchIn.read();
    private static void winnercalculation(char c1, char c2, int player1wins, int player2wins)
    char rock = 'r';
    char paper = 'p';
    char scissors = 's';
    if ((c1 == rock) && (c2 == scissors)) //rock and scissors
    System.out.println("Player 1 Wins!");
    player1wins = player1wins + 1;
    else if ((c1 == rock) && (c2 == paper)) //rock and paper
    System.out.println("Player 2 Wins!");
    player2wins = player2wins + 1;
    else if ((c1 == scissors) && (c2 == rock)) //scissors and rock
    System.out.println("Player 2 Wins!");
    player2wins = player2wins + 1;
    public static void outputresults (int player1wins, int player2wins)
    System.out.println("Player 1 has had "+player1wins+" number of wins");
    System.out.println("Player 2 has had "+player2wins+" number of wins");
    if you need the code for the savitchIn tell me and i will post it

    Local variables are defined inside of methods. Fields are defined outside of methods. (Well there's more to it than that but that's how you can tell them apart.)
    But actually I misread your code. You defined c1 and c2 as local variables in main().
    So your code is fundamentally flawed.
    The easiest thing is to make these fields, static as mambo2 said:
    public class question2a
      static char c1 = 0;
      static char c2 = 0;
      static int player1wins = 0;
      static int player2wins = 0;
      public static void main(String[] args)
    // etcOr, better yet, you could rework your code to actually be a real OOP program.
    Either way, read the manual and learn about field/variable scoping, static vs instance fields, etc.

  • Linking three databases and combing results into one resultset

    Hi Folks,
    I would like to receive input of respectable members of this forum for this problem. Please see details below and let me know what would be the best approach to implement it.
    Problem statement:I need to present data from three Oracle databases in the form of a report based upon parameter values entered by users.
    Problem Details:I have three tables which have same structure but different data. Each table is in a different database, i-e:
    DB1.TableX (say: DB1 holds data for Europe)
    DB2.TableX (DB2 holds data for Asia)
    DB3.TableX (DB3 holds data for North America)
    User Parameters:If p_country = 'ENGLAND' then go and fetch data from DB1.TableX only
    If p_country in ('ENGLAND', 'U.S.A') then go and fetch data from DB1.TableX and DB3.TableX etc.
    Users:Users of DB1, DB2 ,and DB3 will be running this report from their respective dbs so users of DB1 will be able to see data of DB2 and DB3 as well and the vice versa.

    dreporter wrote:
    User Parameters:If p_country = 'ENGLAND' then go and fetch data from DB1.TableX only
    If p_country in ('ENGLAND', 'U.S.A') then go and fetch data from DB1.TableX and DB3.TableX etc.You do not want to hit and process remote tables when they do not have the required rows.
    There's an old feature, dating back to Oracle v7 and still around, called partitioned views. Simply put, you create a view on the tables by using union all.
    A constraint per table specify the expected rows in that table. Oracle's CBO uses this constraint to determine which tables in the partition view to query (assuming of course the constraint column is used).
    For example, you have 5 organisations (same table structure) and a table per organisation. You add a organisation column to each of the tables, with a constraint on the column specifying which organisation's data is in that table. So table1 will have a check constraint on ORG_CODE that says 'BBC', and table2 will have the same constraint with value 'CNN', and table3 will have constraint with value 'SKY', etc.
    The partition view is a plain vanilla view. E.g.
    <i>create or replace view organisations as
    select * from table1 union all
    select * from table2 union all
    select * from table3 union all
    select * from table4 union all
    select * from table5</i>
    If you now query the partition view and use ORG_CODE = 'SKY', then only table3 will be queried and the other tables will not (the CBO prunes the other tables from the view using a special predicate).
    This works pretty well - especially when you only have Oracle Standard Edition. The question though is whether this will work across db links. But it is worth finding out and having a look at this option.

Maybe you are looking for

  • Can I use a mini CD-R in my PowerBook CD Drive?

    Can I use a mini CD-R in my PowerBook cd drive? I wanted to transfer some photo's to the Sony Mini CD-R that came with a PSP to then put on the PSP. But the Mini CD-R is so small I'm afraid to try to slide it into the PowerBook cd slot and not get it

  • Migrating Graphs from Reports 6i to Reports 10g

    While migrating Graphs from Reports 6i to Reports 10g is there a possibility of maintaining the same graphs rather than recompiling them using the Graph Wizard of Reports 10g. I have hundreds of reports with graphs and will be an uphill task to re-dr

  • Time Capsule, Time Machine, Lion, repeater.

    Need to upgrade home network for more space, longer range, upgrade to Lion. Have an existing router, Netgear, that does not reach all areas and devices. Would also like to set up a wireless backup for all computers on network. Of course we need to up

  • Dual boot on an External HDD

    Hello! I need to buy an external HDD but I have a few questions... 1. Can I create two partitions on it, one for storing personal data & other to install OS X? 2. Can I have two partitions: one with OS X & other with Windows 7? Thank you very much! A

  • Home Hub 5 - does not seem to broadcast 2.4ghz ban...

    Hi, I have Infinity with a HH5 and have been having wireless connection problems with certain devices (mobile, laptop WiFi radio).  Following recommendations I have performed a factory reset and set both bands to now have separate SSID's.  Nothing I