Method to find no. of records in a result set.

hi,
tell me the method to find the no. of records in a result set.
I tried getFetchSize() method of ResultSet Interface. But it gives the error method not found in ResultSet interface.
thanks in advance.

You can use cachedRowSet.size() with JDBC 2.0 (I think).
If you have a scrollable result set you use rs.last(), rs.getRow() and can then reposition your cursor using rs.beforeFirst().
You can use the SQL select count(*).
You can loop through the result set and count the rows.
There are many, many posts concerning this topic. Be sure to take advantage of your ability to search the forums so you don't have to wait for an answer. You may want to search now and see if there are more possible solutions.
Good Luck.

Similar Messages

  • Getting the record count from result set

    i'm retreiving the result set using the executeQuery method, now i want to know how many records are there in the result set, that is the record count of the result set.
    one solution to that is to first use the executeUpdate and then use the executeQuery but i think that is not the right way.
    so please tell me is there any method in jdbc to get that thing done
    Tanx

    Hi
    Do you know if your DB supports "insensitive scrolling"?
    SQL generally do, but some don't - I had the same problem with the
    open source version of Interbase from Phoenix...
    Anyway - try creating your statement this way:
    public Statement createStatement(int resultSetType, int resultSetConcurrency)
    throws SQLException
    ...where resultset type should be:
    ResultSet.TYPE_SCROLL_INSENSITIVE
    Then you can do this:
    ResultSet rs = stm.executeQuery(q);
    int size = rs.last(); //this what you looking for?
    rs.beforeFirst();
    while(rs.next()){
    }

  • Removing Duplicate records from this result set

    Here is a challenge question that I was playing with one my free time during work.
    I assume that you have the HR sample database somewhere around (hopefully not in production).
    Let us say that you want to get employees from the employees table whose last name is similar to some other employee last name.
    The easiest way is to join the two tables with a join condition that checks for the last name and the employee id. Here is what I came up with.
    select e1.last_name a , e1.first_name b, e2.last_name c, e2.first_name d
    from employees e1 join employees e2
    on ( e1.last_name = e2.last_name and e1.employee_id <> e2.employee_id)
    order by a;
    The above query returns 10 rows. The first and second are essentially the same. The same applies of 3&4, 5&6, 7&8, and 9&10. The question is: is there any way that allow me to get rid of the duplicate rows using sql only from the result set of this query. I sat on it for 15 minutes and I could not figure it out. I will try looking at again after my work is over.

    Example:
    SQL> column a format a10
    SQL> column b format a10
    SQL> column c format a10
    SQL> column d format a10
    SQL>
    SQL>
    SQL> select e1.last_name a , e1.first_name b, e2.last_name c, e2.first_name d
      2  from employees e1 join employees e2
      3  on ( e1.last_name = e2.last_name and e1.employee_id != e2.employee_id)
      4  where e1.employee_id < e2.employee_id
      5  order by a;
    A          B          C          D
    Cambrault  Gerald     Cambrault  Nanette
    Grant      Kimberely  Grant      Douglas
    King       Steven     King       Janette
    Smith      Lindsey    Smith      William
    Taylor     Jonathon   Taylor     Winston
    SQL>

  • How to get the number of records of a streaming result set

    Hi guys.
    So if it wasn't a streaming result set, I would have done this:
    {noformat}myResultSet<code class="jive-code jive-java">.last();
    {color:navy}*int*{color} numResults = </code>myResultSet<code class="jive-code jive-java">.getRow();
    </code>myResultSet<code class="jive-code jive-java">.beforeFirst();
    </code>{noformat}
    but being a streaming result set, beforeFirst() throws an exception...
    So how do you get the number of records in that result set? I wanna avoid an extra count(*) query, so I would appreciate other solutions than that.

    JoachimSauer wrote:
    vanwil wrote:
    you see, for now I just use a count(*) query to get the number of records, but that's adding a lot of extra waiting time...Iterating over the result twice will surely be slower then doing the count(*).great! so what I got now is actually the fastest way there is... awesome...
    If you get an exception, then you surely have a stack trace. That should tell you what happens, or at least where.com.mysql.jdbc.MysqlIO.checkForOutstandingStreamingData(MysqlIO.java:2066)
    Why do you need to know the number of elements beforehand, anyway?I need to know the number of elements because the incoming data goes into a table. Now of course, I could use ArrayList<String[]> or something, but wouldn't that require more memory resources than Object[][] ?
    No one can tell you that, at least not without more information (say, the stack trace for example).Here's the exception message:
    java.sql.SQLException: Streaming result set com.mysql.jdbc.RowDataDynamic@10c0ef2 is still active. Only one streaming result set may be open and in use per-connection. Ensure that you have called .close() on  any active result sets before attempting more queries.

  • Find SAP table records given a list of tables

    Dear all,
    I have been given a list of table names that I require to provide a report a total record counts for these table.
    given such codes I have can't proceed further as the field symbol that I use is invalid. Please advice how to complete this. Or perhaps any standard system reports to find the total record counts given a specified tables.
    here's the code:
    types : begin of w_dd02l,
               TABNAME type TABNAME,
               totalrec like sy-dbcnt,
            END OF w_dd02l.
    data : wa_dd02l type STANDARD TABLE OF w_dd02l with HEADER LINE.
    data : wr_dd02l type w_dd02l.
    data : totalrecord like sy-dbcnt.
    field-SYMBOLS : <f1> type ANY.
    p_tab is a selection field.
    select tabname from dd02l into CORRESPONDING FIELDS OF TABLE wa_dd02l where tabname in p_tab.
    loop at wa_dd02l into wr_dd02l.
       assign wr_dd02l-tabname to <f1>.
       select count(*) from <f1> into totalrecord.
       wr_dd02l-totalrec = totalrecord.
      write : wr_dd02l-tabname, wr_dd02l-totalrec.
    ENDLOOP.
    <f1> being a field symbol is not recognize as in ABAP dictionary. Here's where I can't proceed.. dear gurus please help.
    Thanks and Regards,
    Andrew

    Pl. check, it's working
    types : begin of w_dd02l,
              TABNAME type TABNAME,
              totalrec like sy-dbcnt,
            END OF w_dd02l.
    data : wa_dd02l type STANDARD TABLE OF w_dd02l with HEADER LINE.
    data : wr_dd02l type w_dd02l.
    data : totalrecord like sy-dbcnt.
    field-SYMBOLS : <f1> type ANY.
    PARAMETERS: p_tab like dd02l-tabname.
    * p_tab is a selection field.
    select tabname from dd02l
                   into CORRESPONDING FIELDS OF TABLE wa_dd02l
                  where tabname = p_tab.
    loop at wa_dd02l into wr_dd02l.
      assign wr_dd02l-tabname to <f1>.
      select count(*) from (<f1>) into totalrecord.      " use  like (<f1>)
      wr_dd02l-totalrec = totalrecord.
      write : wr_dd02l-tabname, wr_dd02l-totalrec, <f1>.
    endloop.

  • How to find the longest record in a table?

    Hello,
    Is there a function to find the longest record in a table? Or is there a data dictionary that would tell you which record contains the longest data?
    I have a table with five columns and one million records. I want to find the record (5 columns combined) with the longest data. Thank you.

    Dear watson2000!
    The function "VSIZE" tells you the number of bytes in the internal representation of a column which means the size of a value within a column. An example of vsize can be found here:
    [http://www.adp-gmbh.ch/ora/sql/vsize.html]
    So I think you should try it with this query to get the size of the longest record:
    SELECT MAX(VSIZE(column1)) +
           MAX(VSIZE(column2))  +
           MAX(VSIZE(column3))  +
           MAX(VSIZE(column4))  +
           MAX(VSIZE(column5)) AS "Maximum Row"
    FROM your_table;To identify the longest record try like this:
    SELECT rowid
    FROM   your_table
    GROUP BY rowid
    HAVING  (MAX(VSIZE(column1)) +
             MAX(VSIZE(column2)) +
             MAX(VSIZE(column3)) +
             MAX(VSIZE(column4)) +
             MAX(VSIZE(column5))) = (SELECT MAX(VSIZE(column1)) +
                                          MAX(VSIZE(column2))  +
                                          MAX(VSIZE(column3))  +
                                          MAX(VSIZE(column4))  +
                                          MAX(VSIZE(column5))
                                   FROM your_table;)I hope that these two queries could be of help to you.
    yours sincerely
    Florian W.
    Edited by: Florian W. on 23.04.2009 20:53

  • How to find the particular record in 1000's of workflow jobs are running

    Hi,
    In a data manager -> in workflow tab>IF a record is in CHECK-OUT MODE there are 1000's of jobs are running in that workflow tab. Can anyone tell me how to find that particular record in that workflow jobs.
    Can anyone show me the difference in getting a record in 5.5 and 7.1

    Hello COTI
    Unfortunatly, SAP MDM doesn't have good ability for  WF search.
    All WF clarify by it's status (unlaunched, avialable, Received, complited, error  etc.)
    For each WF SAP MDM assing unique Job ID and this id will be shown in Job ID field in Data Manager WF Tab.
    You can change WF list order by all WF fields like as Job ID, Step, User, Start etc. and try to find your's WF.
    You can use Java API - this is one of the best solution for WF management and WF mass upload  (for example)
    Regards
    Kanstantsin Chernichenka

  • Is there a way to find a specific record number in PSA?

    I am using BI 7.0. I am getting an error that record no 7487 is invalid. Yet, I do not find a way to go to this record in PSA. It looks like I have to scroll through the whole PSA table for a request and look for a red status. Is there a faster way?

    Hi,
    here you will find a report:
    PSA error records download
    To few PSA table you can use se16 (you can get the PSA table name by right clicking the Datasource ->manage. On the top you will get the PSA table name)
    Additional check:
    finding the error record in datapackage of psa
    Error in PSA  & Update
    Regards
    Andreas

  • Oracle 10g - To find the corresponding record for a certain row

    Hi all,
    The scenario is like this - Suppose I've got a table with 100+ columns. For a certain row inside, I need to find its corresponding record which is in the same table. The way how I define "corresponding" here is - these two rows should be identical in all attributes but only different in one column, say "id" (primary key).
    So how could I achieve this? What I can think of is to fetch all columns of the first row into some pre-defined variables, then use a cursor to loop the table and match the values of the columns of each row to those variables. But given that we've got 100+ rows in the table, this solution doesn't look practical?
    Any advises are greatly appreciated. Thanks.

    something to play with as Solomon suggested (use some other string aggregation technique if you're not 11g yet)
    you'll have to adjust the column_list accordingly
    select 'select ' || column_list ||
           ' from ' || :table_name ||
           ' group by ' || column_list ||
           ' having count(*) > 1' the_sql
      from (select listagg(column_name,',') within group (order by column_id) column_list
              from user_tab_cols
             where table_name = :table_name
           )Regards
    Etbin
    Edited by: Etbin on 25.12.2011 16:53
    Sorry, I'd better leave the forum: the title says you're 10g :(
    Providing a link for replacing listagg: http://www.sqlsnippets.com/en/topic-11787.html

  • Property or method to find missing fonts...

    Hi Everyone,
    Is there any direct property or method to find missing fonts in EPS doucments in Illustrator CS4 like we do in InDesign. I have tried this by doing comparison of document fonts and application fonts to get missing fonts but it won't work.
    Any help would be appreciatable. Thanks in advance.
    Regards
    Thiyagu

    Have you tried a search of this forum… Im sure I posted a work around to this… The simple answer is NO not in the Illustrator DOM you can however read the file as text and the stuff you want is in the Illustrator file comments…

  • Any option is there to find the error record in loop for huge amount of rec

    Hi Guru's,
    In our production system we got a error. While debugging we found one of our loop getting 1 lakh records. One of the record from the internal table having some wrong values because of that its giving a error message. But we are not getting any proper message.
    Now our problem is its very difficult to debug all the records one by one. Even its not possible to give Watchpoint. bze in what situations its giving this error that also not predictable. So how to find the error record?
    Kindly suggest.
    Ananadhan

    Need a lot more info.
    To start with is this CR Designer or some other product?
    I suspect it's classic SAP products like Business One etc., if so please mark as answered and post your question int the correct forum.
    Thank you
    Don

  • How to find count of records based on batch wise.

    Hi All,
    We are working on OWB10gr2. I would like share one requirement. Any one can suggest me how to do it and which is the best way to get accurate information.
    We have 2 schemas’ like nia_src and nia_tgt. currently we are moving data from nia_src to nia_tgt for that reason we implemented some mappings based on requirement. In my source schema (nia_src) having 100 tables with data and similar structure replicated in target schema (nia_tgt).
    In source schema every table having one date field for which record is inserted and based on that field we can find how may records are inserted on particular table ,particular time.
    Same like target also maintaining date fields for tracking purposes.
    We have done some mappings and scheduled also. Every day we are into the target with incremental data. All are working fine not any issues.
    I wanted to know how many records inserted, updated, merged for particular batch
    How can we find?
    Can we find exact information in OWB_REP_OWNER schema on WB_RT_AUDIT?.
    For tracking purposes I need to find those values how many records are available in
    Source table and how many records are populated to the target schema?
    How to find schedule batch count of records table wise for batch wise?
    Please suggest me any one on this.
    thanks and regards,
    venkat.

    RE: based on pre operator can we find count of records. if yes how to do it.
    No, you cannot tell from the pre- operator how many records will be inserted or updated into a mapping. How could you? The mapping hasn't run yet!
    At best (if you have simple mappings with single targets) you could come up with a strategy to have the pre-mapping procedure aware of it's package name, then select from user_source for that package body until you find that first cursor used for the row-based processing, copy the cursor into a local variable, and then execute immediate select count(*) from that cursor definition. But still, all that would get you is the number of rows selected - not inserted / updated / errored etc.
    A post-mapping procedure that is aware of the package name will, however, run prior to package exit so that the package spec is still in memory so you can access the public variables in the package spec. We do that in our standard post-mapping procedure
    CREATE OR REPLACE procedure erscntrl_finalize_prc(
                           p_process_id     in  number,
                           p_process_name   in  varchar2)
    as
          l_numread      number         := 0;
          l_numInserted  number         := 0;
          l_numUpdated   number         := 0;
          l_numMerged    number         := 0;
          l_owb_audit_id number         := 0;
          l_owb_status   number         := 0;
          sqlStmt        varchar2(2000) :=
                               'begin '||
                               '  :1 := '||p_process_name||'.get_selected; '||
                               '  :2 := '||p_process_name||'.get_inserted; '||
                               '  :3 := '||p_process_name||'.get_updated; '||
                               '  :4 := '||p_process_name||'.get_merged; '||
                               '  :5 := '||p_process_name||'.get_audit_id; '||
                               '  :6 := '||p_process_name||'.get_status; '||
                               ' end;';
    begin
          -- we use dynamic SQL to return required audit field values.
          --  This allows us to alter which values we need at a later date
          --  without impacting the deployed mappings.
        execute immediate sqlStmt
        using   out l_numread,   out l_numInserted,  out l_numUpdated,
                out l_numMerged, out l_owb_audit_id, out l_owb_status;
      -- then execute our own logging package.
       owb_mapping_log_pkg.finalize(
                           p_process_id,
                           p_process_name,
                           l_numread,
                           l_numInserted,
                           l_numUpdated,
                           l_numMerged,
                           l_owb_audit_id,
                           l_owb_status
    end;
    /However, even in this case bear in mind that if you run the mapping in set-base mode, all Oracle returns is the number merged which does not give values for the inserted and updated counts. If you really need those values you need to either a) run in row-based mode or row-based-target-only, or come up with some custom queries. For example, in your pre-mapping do a select count(*) from your_target_table, then run the mapping, then get the number merged, then do another select count(*) from your_target_table. With these values and basic math you could tell the number inserted by the growth in the table, and the rest of the number merged must have been updates.
    That being said, if you are playing with dimensions as large as most of the ones I am - there is no bloody way that you want to do two select count(*) statements on each run without a really, really good reason.....
    Cheers,
    Mike

  • SQL Query issue find difference in records

    Hi All,
    I am using oracle 10g. I need urgent help in finding difference in records based on date:
    I have table sales as below:
    salesman SALES_COUNT DATE
    JOHN 20 04/01/2012
    DENNY 15 04/01/2012
    JOHN 30 04/02/2012
    DENNY 30 04/02/2012
    JOHN 45 04/03/2012
    DENNY 50 04/03/2012
    SALES_COUNT is increasing for sales man with date. Its like cumulative count. John has total sales from 04/01/2012 to 04/03/2012 is 50 and same case with Denny. This SALES_COUNT will keep on increasing with dates as sales keep adding in the table for each salesman.
    But i want to have seprate counts for each salesman.
    for e.g: SALES_COUNT JOHN on 04/02/2012 is 30-20 =10
    SALES_COUNT JOHN on 04/03/2012 is 45-30 =15
    SALES_COUNT DENNY on 04/02/2012 is 30-15 =15
    SALES_COUNT JOHN on 04/03/2012 is 50-30 =20
    Please help me with this scenario and let me know if need more information. I will greatly appreciate your help.
    Thanks.

    Does this give you what you want?
    with t as (
         select 'JOHN' salesman, 20 sales_count, to_date('04/01/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'DENNY' salesman, 15 sales_count, to_date('04/01/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'JOHN' salesman, 30 sales_count, to_date('04/02/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'DENNY' salesman, 30 sales_count, to_date('04/02/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'JOHN' salesman, 45 sales_count, to_date('04/03/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'DENNY' salesman, 50 sales_count, to_date('04/03/2012', 'mm/dd/yyyy') sale_date from dual
    select salesman,
           sales_count sales_todate,
           sale_date,
           sales_count - lag(sales_count, 1, 0) over (partition by salesman order by sale_date) daily_sales
    from t
    SALESMAN,SALES_TODATE,SALE_DATE,DAILY_SALES
    DENNY,15,4/1/2012,15
    DENNY,30,4/2/2012,15
    DENNY,50,4/3/2012,20
    JOHN,20,4/1/2012,20
    JOHN,30,4/2/2012,10
    JOHN,45,4/3/2012,15
         

  • How to find if certain record exists from stored procedure

    Hello
    I am not an expert in this and am trying simple thing. I want to find if certain record exists in a table and if so set some boolean variable.
    create or replace procedure findit(param)
    AS
    return_group boolean;
    BEGIN
      myflag := false;
    --here goes my question
    -- say I have SELECT WHATEVER FROM TABLE WHERE BLA = param
    --if it returns at least one record set myflag to true;
    END;Any idea?

    THanks Satyaki_De,
    However, when I put simple SELECT statement in the body of my procedure it does not compile. Actually I should have said that before. So here is my code and where it breaks:
    create or replace procedure close_subjects(study_id varchar2)
    AS
    return_group boolean;
    BEGIN
    dbms_output.enable(1000000);
    FOR current_group IN(
       SELECT DISTINCT group_id from groups WHERE study_id=study_id
    ) LOOP
       FOR current_subject IN(
          SELECT individual_id from groups WHERE group_id=current_group.group_id AND study_id=study_id
       ) LOOP
          return_group := true;
          SELECT INDIVIDUAL_ID FROM ASSIGN WHERE DATE_TIME_ASSIGNED = ( SELECT MAX(DATE_TIME_ASSIGNED) FROM ASSIGN WHERE INDIVIDUAL_ID = current_subject.individual_id ) AND                            ASSIGN_STATUS_ID = 'A';
         IF SQL%RowCount = 0 THEN
           return_group := false;
             dbms_output.put_line(current_subject.individual_id);
          END IF;
       END LOOP;
    END LOOP;
    END;
    /If I comment out SELECT statement and leave dbms_output for testing purposes it works well. As I said I am faaaar from expert and seems to me that I cannot have SELECT in procedure BODY?

  • How to use my findTheHighest method to find the highest value in my two dim

    I am going to create a 13row by 10 colume two dimensional array.
    how to use my findTheHighest method to find the highest value in my two dimensional array.
    .When i compile this program , i got those as following;
    "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsExce
    at TaxEvolution.findTheHighest(TaxEvolution.java:31)
    at TaxEvolutionClient.main(TaxEvolutionClient.java:25)"
    public class TaxEvolution{
    public double[][] salesTaxRates;
    public TaxEvolution()
      salesTaxRates = new double[13][10];
      fillProvinTaxRates();
    private void fillProvinTaxRates()
      for ( int row = 0; row < salesTaxRates.length; row++ )
        for ( int column = 0; column < salesTaxRates[row].length; column++ )
          salesTaxRates[row][column]= (int)(Math.random()*5000) + 1;
    public double findTheHighest()
        double highest = salesTaxRates[0][0];
        for ( int row = 0; row <= salesTaxRates.length; row++ )
          for ( int column = 0; column <= salesTaxRates[row].length; column++ )
             if ( salesTaxRates[row][column] >= highest )
                   highest = salesTaxRates[row][column];
        return highest;   
    public double[][] arrayTaxEvolution()
      double[][] returnTaxRates = new double[13][10];
      for ( int row = 0; row < salesTaxRates.length; row++ )
        for ( int column = 0; column < salesTaxRates[row].length; column++ )
          returnTaxRates = salesTaxRates;
      return returnTaxRates;
    public class TaxEvolutionClient{
    public static void main( String[] args ){
      TaxEvolution protaxRateList = new TaxEvolution();
      double[][] taxRateList = protaxRateList.arrayTaxEvolution();
        for ( int i = 0; i < taxRateList.length; i++ )
          for ( int j = 0; j < taxRateList[0].length; j++ )
            System.out.print( taxRateList[i][j] + "\t" );               
            System.out.print( protaxRateList.findTheHighest + "\t" );
    }

    Multiposted
    http://forum.java.sun.com/thread.jspa?threadID=699057&tstart=0

Maybe you are looking for