Number of rows returned by the resultset is wrong

Hi All,
I have pasted the code i used for JDBC. The problem is the number of rows returned by the resultset is 5 times that of the original data. Is something wrong with my code. Can anyone pls point out the mistake I have done if any.
    public ArrayList dataBreakup(String team, int monthNo, int year) {         String sqlDataBreakup = "";         Connection con1 = null;         Statement stmt = null;         ResultSet rs = null;         ArrayList data = new ArrayList();         int noRows = 0;         Calendar cal = Calendar.getInstance();         Calendar cal2 = new GregorianCalendar(cal.get(Calendar.YEAR), monthNo, 1);         int days = cal2.getActualMaximum(cal2.DAY_OF_MONTH);         String start_date = "01-Jan-" + year;         String end_date = days + "-" + monthName[cal2.get(Calendar.MONTH)] + "-" + cal2.get(cal2.YEAR);         System.out.println("START: " + start_date);         System.out.println("END: " + end_date);         databaseConnection dbObject = new databaseConnection();         try {             con1 = dbObject.GetConnection();             stmt = con1.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);             sqlDataBreakup = "Select * from EXPENSE_STORE WHERE " +                     "team='" + team + "'AND category != 'Pending PO''s' AND ACCOUNTING_DATE " +                     "BETWEEN to_date('" + start_date + "') AND to_date('" + end_date + "')";             rs = stmt.executeQuery(sqlDataBreakup);                         ResultSetMetaData rsmd = rs.getMetaData();             int numColumns = rsmd.getColumnCount();             data.add(numColumns);             for (int i = 1; i < numColumns + 1; i++) {                 data.add(rsmd.getColumnName(i));             }                        while (rs.next()) {                                noRows++;                 for (int i = 1; i < numColumns + 1; i++) {                     switch (rsmd.getColumnType(i)) {                         case java.sql.Types.NUMERIC:                             data.add(rs.getFloat(i));                             break;                         case java.sql.Types.DATE:                             data.add(rs.getDate(i));                             break;                         default:                             data.add(rs.getString(i));                             break;                     }                                    }                     }             data.add(1, noRows);             rs.close();         } catch (SQLException SQLe) {             System.out.println("DumpData() : SQL Exception" + SQLe.getMessage());             SQLe.printStackTrace();         } catch (Exception e) {             System.out.println("DumpData() : Other Exception");             e.printStackTrace();         } finally {             dbObject.CloseConnection(con1);         }         return data;     }
Thanks
Cheers N...

Only thing i can say is
try the following
replace your function by this one and tell us the console output of the same
public ArrayList dataBreakup(String team, int monthNo, int year) {
        String sqlDataBreakup = "";
        Connection con = null;          
        ArrayList data = new ArrayList();
        int noRows = 0;
        Calendar cal = Calendar.getInstance();
        Calendar cal2 = new GregorianCalendar(cal.get(Calendar.YEAR), monthNo, 1);
        int days = cal2.getActualMaximum(cal2.DAY_OF_MONTH);
        String start_date = "01-Jan-" + year;
        String end_date = days + "-" + monthName[cal2.get(Calendar.MONTH)] + "-" + cal2.get(cal2.YEAR);
        System.out.println("START: " + start_date);
        System.out.println("END: " + end_date);
        System.out.println("START: " + start_date);
        System.out.println("END: " + end_date);
        databaseConnection dbObject = new databaseConnection();
        try {
            con = dbObject.GetConnection();          
            sqlDataBreakup = "Select * from EXPENSE_STORE WHERE " +
                    "team = '"+team+"' AND category != 'Pending PO''s' AND ACCOUNTING_DATE " +
                    "BETWEEN to_date('"+start_date+"') AND to_date('"+end_date+"')";
               System.out.println("-----------sql starts---------------");
               System.out.println(sqlDataBreakup);
               System.out.println("-----------sql ends---------------");
            PreparedStatement pstmt = con.prepareStatement(sqlDataBreakup);
               pstmt.setString(1, team);
            pstmt.setString(2, start_date);
            pstmt.setString(3, end_date);
            ResultSet rs = pstmt.executeQuery();
            ResultSetMetaData rsmd = rs.getMetaData();
            int numColumns = rsmd.getColumnCount();
            data.add(numColumns);
            for (int i = 1; i < numColumns + 1; i++) {
                data.add(rsmd.getColumnName(i));
            while (rs.next()) {
                noRows++;
                for (int i = 1; i < numColumns + 1; i++) {
                    switch (rsmd.getColumnType(i)) {
                        case java.sql.Types.NUMERIC:
                            data.add(rs.getFloat(i));
                            break;
                        case java.sql.Types.DATE:
                            data.add(rs.getDate(i));
                            break;
                        default:
                            data.add(rs.getString(i));
                            break;
            //data.add(1, noRows);
               System.out.println("no of Rows : " +noRows );
        } catch (SQLException SQLe) {
            System.out.println("DumpData() : SQL Exception" + SQLe.getMessage());
            SQLe.printStackTrace();
        } catch (Exception e) {
            System.out.println("DumpData() : Other Exception");
            e.printStackTrace();
        } finally {
            dbObject.CloseConnection(con);
        return data;
    }and try running the sql printed on the screen in your db and then let us know the result.
in this code i have removed some of your code in order to simplify the problem.

Similar Messages

  • Getting the no. of rows returned from the resultset

    Could somebody tell how can I get the count of rows from the resultset object.
    Thanks a lot in advance

    hmmm 20,710 topics and 69,000 odd posts and no one has EVER asked this question before.. it's a miracle....
    or maybe it has been asked and dealt with approx... 11,000 times.
    here is a discussion from 1998 for example http://forum.java.sun.com/thread.jsp?forum=48&thread=83958

  • Limiting number of rows returned by SQVI

    I've created a query in SQVI and I need to limit the number of rows returned by the query.  (I'm using the query as an exploratory tool, and it's not easy to predict how many records will be returned based on the selection fields I'm using.)
    Is there any way to add a 'Maximum No. of Hits' field to the SQVI selection screen similar to what is found when using SE16?
    Thanks,
    Bob

    It's not surprising that you are confused because the documentation doesn't bother to explain what the "fetch size" actually is, it just says that setFetchSize sets it and getFetchSize gets it. As I understand it from some other documents I read about JDBC, the fetch size is a number that may be used internally by the JDBC driver. Here's an example of how I understand it (others, I know you will feel free to correct me if you disagree):
    When the driver produces a result set with a very large number of records, it has to generate those records and deliver them to the system that requested them. If the database is not on the same system, then those records must all travel over the network. It could be a performance problem if you had to wait for (say) 80,000 records to travel across the network. Enter the fetch size. If you set the fetch size to 100, then the driver will bring the records across in batches of 100, as the program calls for them. Now, this buffering is transparent to your program; the driver doesn't tell you that it's getting another batch and you can't tell it to get another batch. So it is not a solution to the problem that everybody has here, namely how to display your records 10 per page and allow the user to go back and forth among those pages, like search engines do.

  • Number of rows returned for a report

    I want to create reports on serveral tables, the number of rows in these tables varies a lot (5, 5000, and the other one can have 10000+ rows).
    In the Reports Attributes page, is there a way to set the max number of rows return to the number of rows of the table? For example, for a table that has 10000 rows now, may grow to 20000 rows in the near future. If I specify the "Max Row Count" to 20000, the number may be outgrown yet again soon. If I can specify "Max Row Count" to "Current number of rows in the table" then this problem will not happen. Can it be done?

    that "Max Row Count" attribute is used to limit the number of rows returned by a htmldb report region. in your case it sounds as if you want to show all available rows all the time. in that case you'd be fine to just put a very large number into that field like 4million. that way you'd always show all your rows.
    hope this helps,
    raj

  • Getting the number of rows returned from ResultSet

    Hi,
    Does anyone know a method to get the number of rows returned with a query using the Resultset class?
    Thanks.

    Hi 281080,
    If your database and JDBC driver support it, in order to use the solution that da-alexj has suggested, you need to create a 'scrollable' "ResultSet" -- the javadoc for method "createStatement()" (in class "java.sql.Connection") has more details.
    However, I have found with Oracle 8.1.7.4 database and Oracle (thin) JDBC driver, that part of their implementation of the "last()" method (in class "java.sql.ResultSet") is to actually iterate through the entire "ResultSet" in order to reach the last row. If your "ResultSet" is very large (I tested it with a 100,000 row "ResultSet"), this will take a long time.
    Just wanted to make you aware of that.
    Of-course, this may be irrelevant to you since I didn't see any mention in your post of what database and JDBC driver you are using.
    Hope this has helped you, anyway.
    Good Luck,
    Avi.

  • Need to know how to limit the number of rows returned on Oracle

    MS SQL Server has a command called 'set row count'.
    We are trying to find similar one on Oracle.
    What we are trying to do is that instead of using rownum in the query statement, we would like to find way to limit the number of rows returned. I understand that we can use JDBC resultSet object, but that's not what we want.
    I know Oracle has one called arraysize, but this would not limit the number of rows returned either.
    Pease help.
    Thanks

    I understand that we can use JDBC resultSet object, but that's not what we want.I'm not sure which feature of ResultSet you use and which not.
    But if this question has anything to do with JDBC (that's the forum where you put it), I'd recommend to use Statement.setMaxRows(). This will limit the count of rows which your statement will fetch into it's ResultSet.

  • How can I limit the number of rows returned by a select stat

    How can I limit the number of rows returned by a select
    statement. I have a query where I return the number of stores
    that are located in a given area.. I only want to return the
    first twenty-five stores. In some instances there may be over
    200 stores in a given location.
    I know is SQL 7 that I can set the pagesize to be 25....
    Anything similiar in Oracle 8i?
    null

    Debbie (guest) wrote:
    : Chad Nale (guest) wrote:
    : : How can I limit the number of rows returned by a select
    : : statement. I have a query where I return the number of
    : stores
    : : that are located in a given area.. I only want to return the
    : : first twenty-five stores. In some instances there may be
    : over
    : : 200 stores in a given location.
    : : I know is SQL 7 that I can set the pagesize to be 25....
    : : Anything similiar in Oracle 8i?
    : If you are in Sql*Plus, you could add the statement
    : WHERE rownum <= 25
    : Used together with an appropriate ORDER BY you
    : could get the first 25 stores.
    Watch out. ROWNUM is run before ORDER BY so this would only
    order the 25 selected
    null

  • Can I limit the number of rows returned on a Select?

    Can I limit the number of rows returned on a Select statement? I would be using JDBC in a Java program.

    Use Java prepared statements with the equivalent of this SQL*plus script:
    VARIABLE n number
    EXEC :n := 3;
    SELECT rownum FROM all_objects WHERE rownum <= :n;
        ROWNUM
             1
             2
             3
    EXEC :n := 5;
    SELECT rownum FROM all_objects WHERE rownum <= :n;
        ROWNUM
             1
             2
             3
             4
             5

  • Get the number of rows returned by a dataProvider

    hi
    I am using a [Bindable] variable that I am setting and using
    as a DataProvider (coming from a web service) for a DataGrid within
    my Flex 2 application.
    is there a way of knowing the amount of rows that the
    dataProvider is returning???
    as I want to do a calculation to set the height of the
    dataGrid depending on the amount of rows being returned by the
    dataGrid!
    any suggestions...?
    Thanks,
    Jon.

    that only seems to count the default number of rows (height)
    of the datagrid..... i.e. 7.
    I need to know the number of rows being returned from the
    dataProvider - i.e. the number of rows coming through the
    webService from the database etc.....
    Thanks,
    Jon.

  • How do you limit the number of rows return from query?

    How do you limit the number of rows return from query? Do all databases support this kind of feature?

    i think the standard is limit
    to get the top 30
    select * from mytable LIMIT 30;returns the first 30 rows
    also if you want a range
    select * from mytable LIMIT 10,30;returns 30 rows starting from 10
    this last one is useful for displaying ranges... something similar happens in these forums when viewing topics and messages

  • How to get number of rows return in SELECT query

    i'm very new in java, i have a question:
    - How to get number of rows return in SELECT query?
    (i use SQL Server 2000 Driver for JDBC and everything are done, i only want to know problems above)
    Thanks.

    make the result set scroll insensitve, do rs.last(), get the row num, and call rs.beforeFirst(), then you can process the result set like you currently do.
             String sql = "select * from testing";
             PreparedStatement ps =
              con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
             ResultSet rs = ps.executeQuery();
             rs.last();
             System.out.println("Row count = " + rs.getRow());
             rs.beforeFirst();~Tim
    NOTE: Ugly, but does the trick.

  • How to restrict number of rows returned in a query

    Hi frnds,
    I'd like to restrict number of rows returned by my query to some 10 rows. how to do that.When I try doing with the rownum<10 its giving results for a particular dept and that too some 6 rows only...btw I'm grouping my table and includes joins from many a table and am ordering the table results by a column.. How to do this..

    776317 wrote:
    Hi frnds,
    I'd like to restrict number of rows returned by my query to some 10 rows. how to do that.When I try doing with the rownum<10 its giving results for a particular dept and that too some 6 rows only...btw I'm grouping my table and includes joins from many a table and am ordering the table results by a column.. How to do this..
    TELL ME HOW MANY ROWS YOU HAVE IN TABLE?
    Because you have only *6 rows* in you column, if you less than 10 rows then it displays only containied/exist rows. nothing much
    select ename,empno from emp where rownum < 10;Thanks

  • Restrict number of rows returned in a report

    Hi All
    Does anyone know how to restrict the number of rows returned in a report eg. I want to do a couple of reports based on opportunities/products and return only the top 5 or 10???
    Thanks
    Gail

    Sorry just answered my own question by using the 'is in top' colum filter!

  • How can i now the number of rows afected by the last query?

    how can i now the number of rows afected by the last query?
    For example:
    i made this update :
    update trl_trial set status = 1 /* Validation */
    where trial_id = cobject_id
    and status = 0; /* Initial */
    if NUMBERS_OF_ROWS = 0 then
    end if;
    how can i do this?
    thank u!!!!

    how can i now the number of rows afected by the last query?
    For example:
    i made this update :
    update trl_trial set status = 1 /* Validation */
    where trial_id = cobject_id
    and status = 0; /* Initial */
    if NUMBERS_OF_ROWS = 0 then
    end if;
    how can i do this?
    thank u!!!! Do the following :
    update trl_trial set status = 1 /* Validation */
    where trial_id = cobject_id
    and status = 0; /* Initial */
    if(SQL%ROWCOUNT = 0 ) then
    else
    end if;
    you can also declare a variable and do
    myvar := SQL%ROWCOUNT;
    SQL%ROWCOUNT returna the # of rows afected by any sql
    statement, like DELETE, UPDATE

  • Number of rows returned in a query

    Is there a way to get the number of rows returned from a query without itterating through the itterator?
    Thanks,
    Yon

    No.
    Because rows are not all returned until you start interating.
    Some times I have seen people do a count query before the normal query, this helps out if you need a count to set things up.

Maybe you are looking for

  • IE returns "Cannot find server" page during Servlet processing

    I have 2 JSP applications, that require a certain amount of server processing before they complete. For small amounts of information, both of these applications work fine. However, with larger amounts of processing, IE seems to timeout or have a prob

  • Invoice item condition read

    Hi experts, I need to retreive the "Net Vlaue 1 (w/o freight)" (step 500) of the "ZH00" condition (step 415) which is on the material line item of the invoice. When I check the KONV table, It's only giving me the "ZH00" values but not the values for

  • How to create recovery disc that have factory default in H320?

    Hi I just bought a ideacentre H320. I want to prepare recovery discs, but when I do so, I am only given the option to backup the "current system". I did not see option in such as "Factory Default Recovery Disc" as I see in OneKey Recovery 7.0 (Mine o

  • User Template folder on server

    We have changed in the office from 10.6 -10.8 with Pages 09 to 10.9 and Pages 5.2 With the old pages we had an alias of the server folder containing the templates in the template folder in teh users library. I tried everything I found with google but

  • Cluster resource authorizations

    Is there anyway to limit a role to only control specific cluster resource groups? I want to give application admins the capability to take their resource groups offline or switch nodes. If I add the solaris.cluster.admin authorization, it will still