Getting virtual memory error when fetching records from database

HI,
I am using Oracle as Database and the Oracle JDBC driver. I have simple code which is a select statement but the problem is the resultset dies while fetching the data i.e. 5,50,000. And it gives me the memory error as its storing all in the memory. One of the way which i have serched in the old threads is using the batch method fetching rows at a time but can you tell me how to implement in my code. I am pasting my code.
The overall functionality of my code is that it's reterving data from database and generating an XML file that would be validated with a DTD.
//My Code
public class Invoicef3 implements ExtractF3 {
     final String queryString = "select * from hsbc_f3_statement
order by bill_no, duplicate,
invoice_address1,
invoice_address2,
invoice_address3,
invoice_address4,
invoice_address5,
invoice_address6,
main_section, order_1, page,
section, product_category,
sub_sect_1, order_2,
sub_sect_2, child_product,
sub_sect_3, account,
line,entry_date, currency, tier";
     public ArrayList process() {
          Connection con = null;
          Statement stmt = null;
          ResultSet rset = null;
          ArrayList arr1 = null;
          try {
               con =
ConnectionManager.getConnection();
               stmt = con.createStatement();
          rset = stmt.executeQuery(queryString);
               arr1 = new ArrayList();
               while (rset.next()) {
                    arr1.add(
                         new F3StatementExtract(
                              rset.getString(1),
                              rset.getInt(2),
                              rset.getString(3),
                              rset.getInt(4),
                              rset.getInt(5),
                              rset.getString(6),
                              rset.getInt(7),
                              rset.getString(8),
                              rset.getInt(9),
                              rset.getString(10),
                              rset.getInt(11)));
               rset.close();
               stmt.close();
          } catch (SQLException e) {
               e.printStackTrace();
          } finally {
               ConnectionManager.close(rset);
               ConnectionManager.close(stmt);
               ConnectionManager.close(con);
          return arr1;
}

The problem is that you are fetching and processing all the rows for the query, which the VM cannot handle given the heap space available. The points you could think over are:
* Allocate more heap memory (this would help only to a limited extent)
* Try to process only a few records at a time instead of all of them (there is actually no need to process all the records at a time. Try processing records in lots of say 1000)
* Avoid selecting all the columns [SELECT *] from the table, if all of them are not going to be used.
There is a slight change i have done in the code is that i am using two quereies now one is fetching all the Bills and the secondquery is fetching all the data for the relevant BILL.
//My Code
public class Invoicef3 implements ExtractF3 {
     /*Query to get distinct bill numbers*/
     final String queryString1 =
          "select distinct(bill_no) from hsbc_print_bills";
     /*Query to get distinct bill numbers statement details*/
     final String queryString =
          "select * from hsbc_f3_statement where bill_no='";
     public ArrayList process() {
          Connection con = null;
          Statement stmt = null;
          ResultSet rset = null;
          ArrayList arr1 = null;
          ArrayList arr2 = null;
          try {
               con = ConnectionManager.getConnection();
               stmt = con.createStatement();
               rset = stmt.executeQuery(queryString1);
               arr1 = new ArrayList();
               while (rset.next()) {
                    arr1.add(new F3BillExtract(rset.getString(1))); //generating the Bill_No's
               System.out.print(arr1.size());
               rset.close();
               stmt.close();
               for (int i = 0; i < arr1.size(); i++) {
                    stmt = con.createStatement();
                    rset =
                         stmt.executeQuery(
                              queryString
                                   + (((F3BillExtract) arr1.get(i)).getBill_No())
                                   + "'");
                    arr2 = new ArrayList();
                    /*Fetching the statement Details of the particular Bill_No*/
                    while (rset.next()) {
                         arr2.add(
                              new F3StatementExtract(
                                   rset.getString(1),
                                   rset.getInt(2),
                                   rset.getString(3),
                                   rset.getInt(4),
                                   rset.getInt(5),
                                   rset.getString(6),
                                   rset.getInt(7),
                                   rset.getString(8),
                                   rset.getInt(9),
                                   rset.getString(10),
                                   rset.getInt(11),
                                   rset.getString(12),
                                   rset.getFloat(13),
                                   rset.getDate(14),
                                   rset.getString(15),
                                   rset.getInt(16),
                                   rset.getString(17),
                                   rset.getString(18),
                                   rset.getString(19),
                                   rset.getString(20),
                                   rset.getString(21),
                                   rset.getString(22),
                                   rset.getString(23),
                                   rset.getString(24),
                                   rset.getString(25),
                                   rset.getString(26),
                                   rset.getString(27),
                                   rset.getString(28),
                                   rset.getString(29),
                                   rset.getString(30),
                                   rset.getDate(31),
                                   rset.getDate(32),
                                   rset.getDate(33),
                                   rset.getDate(34),
                                   rset.getString(35),
                                   rset.getString(36),
                                   rset.getString(37),
                                   rset.getString(38),
                                   rset.getString(39),
                                   rset.getString(40),
                                   rset.getFloat(41),
                                   rset.getFloat(42),
                                   rset.getFloat(43),
                                   rset.getInt(44),
                                   rset.getFloat(45),
                                   rset.getString(46),
                                   rset.getString(47)));
                    rset.close();
                    stmt.close();
                    ((F3BillExtract) arr1.get(i)).setArr(arr2);
          } catch (SQLException e) {
               e.printStackTrace();
          } finally {
               ConnectionManager.close(rset);
               ConnectionManager.close(stmt);
               ConnectionManager.close(con);
          return arr1;
}

Similar Messages

  • Fetch records from Database based on Input value

    Hi Experts,
    In my mobile application, I have designed one input field with F4 help or input assist. I need to fetch records from database based on that input and need to display records in table.
    My question is:
    How to fetch the records from database/back end based on the input value and display them as table format as we are doing in SAP ABAP?
    Here, I need to fetch the records based on input value available in the UI screen and pass that value to gateway, fetch the records from database and need to bind with table in SAPUI5.
    Kindly share the whole process flow with sample code for this requirement. Hope I have explained the requirement in detail.
    Thanks In Advance..
    Regards,
    Arindam Samanta.

    Hi,
    Try something like this.
    In this, I am passing From date, To date, RelGrp, RelStr, Uname as input. Then I am storing those values in variables and passing this data in Odata request.
    OData.read({ requestUri: "http://xxxx:8000/sap/opu/odata/sap/Z188_PO_SRV/pos?$filter=Docdate le datetime'"
                    + todateformat+"T00:00:00' and Docdate ge datetime'"
                    + fromdateformat+"T00:00:00' and RelGrp eq '"
                    + relcode +"'and RelStr eq '"
                    + relstg +"'and Uname eq '"
                    + username+ "' "},
      function (data) {
    console.log(data);
    When we are giving correct inputs it will goes to Success function and get the data from back end.
    In console we can see the data.
    Hope this will helps to you.
    Thanks&Regards
    Sridevi

  • Virtual memory exhausted when compiling packages from AUR

    Recently I've seen this error more and more often. When I tried compiling some packages from AUR, I ended up getting "virtual memory exhausted" error. The first time it happened with clementine-git, then android-studio. Can I do something about it?

    I am also facing the same problem.  I am trying to install a package, and the installations aborts saying 'virtual memory exhausted'. The RAM is 2 GB and i have alloted 2 GB as swap.  Things i have tried so far
    -install  using yaourt
    -install using  makepkg.
    -change  TMPDIR to HDD.
    Even when i tried it without any window manager to start, limiting the RAM usage, the problem still persists. The only way is to allot an extra swap space, but that would mean that i will have to delete a partition, which is not a feasible solution. Is there anything else one could do. ?
    if it helps,
    ulimit -a
    core file size          (blocks, -c) 0
    data seg size           (kbytes, -d) unlimited
    scheduling priority             (-e) 20
    file size               (blocks, -f) unlimited
    pending signals                 (-i) 16033
    max locked memory       (kbytes, -l) 64
    max memory size         (kbytes, -m) unlimited
    open files                      (-n) 1024
    pipe size            (512 bytes, -p) 8
    POSIX message queues     (bytes, -q) 819200
    real-time priority              (-r) 0
    stack size              (kbytes, -s) 8192
    cpu time               (seconds, -t) unlimited
    max user processes              (-u) 16033
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited

  • Time out error while fetching records from table BKPF

    Hi,
    I am fetching records from table BKPF using BUKRS & AWKEY in where clause. Query is as follows:
        SELECT BELNR  XBLNR  AWKEY
        FROM   BKPF
        INTO TABLE L_I_BKPF_TEMP
        PACKAGE SIZE 500
        WHERE BUKRS LIKE L_C_EG
        AND   AWKEY IN L_R_AWKEY .
          APPEND LINES OF L_I_BKPF_TEMP TO I_BKPF .
        ENDSELECT .
    Program is giving time out error. There are 25628 records in range L_R_AWKEY , i m fetching 500 records at a time using  PACKAGE SIZE. But the execution of prog stops on this query.
    Please suggest something to overcome this problem.

    Hi
    Rui is right,
    if you need to get the data by  operation parameters u have to use the fields AWTYP and AWKEY.
    In this selection u can omit the company code.
    SELECT BELNR XBLNR AWKEY FROM BKPF
           INTO TABLE L_I_BKPF_TEMP
                 PACKAGE SIZE 500
                      WHERE   AWTYP = <......> "<------------
                             AND AWKEY IN L_R_AWKEY .
           APPEND LINES OF L_I_BKPF_TEMP TO I_BKPF .
    ENDSELECT .
    Max

  • Getting Virtual Memory Error in 4i Viewer/Plus

    I was able to get results yesterday with both Viewer and Plus, but not today. The user version still works.
    I can connect and see the workbooks. It says that it is running, but gets "An error occurred while attempting to perform operation".
    I set up a trace file and see the following:
    Virtual Memory Error : Maximum Heap Space Exceeded, increase the memory size under Cache Options
    Any thoughts? Where are the Cache Options set from? This is the Viewer, not client.

    I was able to get results yesterday with both Viewer and Plus, but not today. The user version still works.
    I can connect and see the workbooks. It says that it is running, but gets "An error occurred while attempting to perform operation".
    I set up a trace file and see the following:
    Virtual Memory Error : Maximum Heap Space Exceeded, increase the memory size under Cache Options
    Any thoughts? Where are the Cache Options set from? This is the Viewer, not client.

  • Virtual Memory Error when accessing store

    I buy a lot from the store and I am unable to download or purchase since upgrading because of a constant virtual memory error popping up. This only occurs when I access the store. I have read trouble shooting procedures recommended by others on here but all have failed so far. I do know that it's not my system. I definitely hope this issue is remedied with an updated version soon.

    I take it there is no current solution for this issue? Any assistance would be greatly appreciated.
    Thank you in advance, John

  • Why do I keep getting low memory errors when opening files in Bridge CS4? (New computer running i7 2.40GHz, 12GB RAM)

    Just picked up a new computer which has a lot more RAM than my old computer bu I keep getting low memory errors. Never had this issue on my old computer, any ideas?

    Windows or Mac?  (If the former, I can't be of any help.)  Exact version of your OS?
    How much available disk space?  Do you have a separate hard drive for Photoshop's scratch file?

  • Problem When deleting record from database

    Hi ,
    I have a question. Firstly I'm using VB
    I have a problem about deleting any record from access database , That's the code I'm use it for add new item and it's work but it's not work when I tried to edit any rows " it's not want to Save" but work for add new Item.
    Try
    Me.Validate()
    Me.CustomerBindingSource.EndEdit()
    Me.CustomerTableAdapter.Update(Me.KonoDataSet.Customer)
    MsgBox("Update Successful")
    Catch ex As Exception
    MsgBox("Update Failed")
    End Try
    And That's my code for Deleting any record from database But it's not work and that's a problem.
    CustomerBindingSource.RemoveCurrent()
    CustomerBindingSource.EndEdit()
    Me.CustomerTableAdapter.Update(Me.KonoDataSet.Customer)
    Can anybody help me about that issue ?

    Hi kono20006000,
    Your issue seems really strange. I would recommend you make a troubleshooting.
    1.Made sure your code works with the single copy of the database. You could check if it scans hard drive for the database file name and check if it modifies dates on found files. You could check if you operate with the same database.
    2. Use the application update the record at the form_load event to see if it would work correctly.
    3.Check the table in update statement and the table in add statement.
    Best Regards,
    Edward
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

  • Maximum Open cursor  Exceeded error when deleting records from a table

    I have a strange problem.
    I have a table EMP_MASTER . Whenever I am trying to delete a record from this table, I am getting Maximum no. of open cursor exceeded error. But this error doesnot come when i delete from any other tables. And no. of open cursor is much lesser than OPEN_CURSOR parameter.
    All other tables (around 700) has foreign key constraint to this EMP_MASTER table for created_user paramater.
    Is it some thing like, when I am trying to delete a record from EMP_master, implicit cursor opens up and checks all referenced tables. and that limit gets exceeded ?
    Please help.
    Thanks,
    Raj

    Raji03 wrote:
    There is no trigger defined for this table.
    Is there a limit on which no.of references made to a column ? Because one column in this field, Emp no is being referenced in almost every other table. around 700 tables. Will it have any adverse effect ?That should have nothing to do with your problem directly. Again, those tables could have triggers defined on them and you are leaking cursors in one of those triggers (wild guess).
    An example of a table with many many others foreign key'd to it.
    create table parent_of_everything
       column1 number primary key
    insert into parent_of_everything select level from dual connect by level <= 1000;
    commit;
    --create 1000 tables all with foreign keys to the parent_of_everything
    begin
       for i in 1 .. 1000
       loop
          execute immediate 'create table child_' || i || ' (column1 number, column2 number, constraint child_' || i || '_fk foreign key (column1) references parent_of_everything (column1) on delete cascade)';
          execute immediate 'insert into child_' || i || ' select level, mod(level, ' || i || ') from dual connect by level <= 1000';
          commit;
       end loop;
    end;
    TUBBY_TUBBZ?delete parent_of_everything;
    1000 rows deleted.
    Elapsed: 00:02:53.03No problems were had (none were expected).
    Cleanup script.
    --remove the 1000 child tables
    begin
       for i in 1 .. 1000
       loop
          begin
             execute immediate 'drop table child_' || i || ' purge';
          exception when others
             then
                null;
          end;
       end loop;
    end;
    /

  • Error when creating record from portal into MDM using MDM API's

    Hi All,
    When trying to create a new record from Portal we are getting the below error. It is working fine till yesterday.
    We are using MDM API's from webdynpro java for creating.
    What could be the reason for this. Not sure whether this error is ocuring for all the users or for single user.
    "Exception: CommandException com.sap.mdm.commands.CommandException: com.sap.mdm.internal.protocol.manual.ServerException: Database command execution error. A SQL statement failed to execute. The actual error may have been written to a log file."
    Please help to resovle this.
    Thanks
    Satish

    Hello Satish
    Suppose your Portal was upgrated
    if it right -  search and deploy new mdm packages
    Regards
    Kanstantsin

  • I'm getting a copy error when moving books from Digital Editions to my kobo?  How do I fix this?

    I'm getting the following error message when trying to move books from Digital Editions to my Kobo.  I get the green + sign and when I release my mouse this is what I get:  can anyone help

    The response did not solve my problem whatsoever.  I can select an EPUB book from the library it goes into Digital Editions and every selection that I've make tells me it can't be copied.  There must be some setting that I'm missing but this has never happened before.  I had to reload Adobe since my laptop had issues.  I've been using Adobe and my Kobo for 3 years now without an issue.  I even tried downloading the free books that Adobe offers and got the same response.
    It would actually be nice to speak to someone over the phone instead of having to communicate via this forum.  It's very frustrating.  PLEASE HELP to resolve this issue.

  • LabVIEW Memory full while fetching data from database

    Hi,
    In my program I need to sync some data from client PC as per the selected time frame.
    But while fecthing the data from the clinet database, my application is hanging and when I run it with code I get the 'LabVIEW memory full' error message.
    Kindly suggest to overcome this problem.

    Fetching the entire database is probably not a good idea.  You should narrow down how much you read at a time.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Unable to fetch records from database with huge selection screen

    Hi all,
    I have 20 fields from selection screen.
    I have a z table with these 20 fields .
    Now with the values entered in the selection screen i have to fetch the records from the z table.
    All fields in the selection screen are not mandatory, the user may or may not enter the values.
    I have to fetch the records based on the values entered.
    I wrote a select with where condtion to all those 20 fields. but its not retreving the records.
    All the fields in the selection screeen are parameters.
    Could you help me on this, please. I wrote in the where conditon with field1 = value AND field 2 = value.. etc... field20 = value.
    Please guys help me out.
    KV.
    Edited by: Nithin Kumar on Mar 18, 2008 8:48 AM

    Guys,
    I have a problem with the select query.
    as i said i have 20 fields, ranges are working for few fields.
    But i have couple of fields as descriptions. So i have to fetch the records for pattenr as well.
    Means, user can enter in the description............. like    "ab". So in the description if there is anything   with 'ab' it should fetch.
    it works with a LIKE statement with % symbols.
    but it doenst work with   ranges and patterns in same select. I mean the below is not working.
      SELECT  *
             FROM crmd_orderadm_h
             INTO table itab
             WHERE object_id IN r_obj AND
                   process_type IN r_pro AND
                   description LIKE s_des.
    r_obj, r_pro are ranges  and s_des is the pattern, ex: %ab%.              so in this case how it has to be done... could you please help me on this.. the other fields could be blank( r_obj and r_pro).. 
    kindly help me out......
    KV

  • To Fetch records from database ..in case if there thousands of records

    Hi All,
          Suppose i have several thousands of records in the database.I want a select statement which can   retrieve first 5000 rows and last 5000 rows simultaneously.
    Can anybody please tell me how to select it from the database.
    Its urgent so hence kindly please let me know .
    Thanks,
        Neethu

    select * from db into table itab
    where <condition>
    upto 5000 rows
    sorted by primary key.
    select * from db appending table itab
    where <condition>
    upto 5000 rows
    sorted descending by primary key.
    *reward if solved*

  • Memory Error when trying to paste art into PS CS4 vanishing point grid

    I get a memory error when trying to paste art into PS CS4 vanishing point grid.
    "Photoshop.exe application Error The instruction at 0x7755886b referenced memory at 0xffffffff. The memory could not be read. Click on OK to terminate the program"
    I have plenty RAM, HD space, and virtual RAM/Cache in PS prefs.
    Any suggestions?

    Try disabling the Aeros theme by selecting one of the Windows Classis Themes under desktop customization.  This seemed to fix the problem for me.

Maybe you are looking for

  • Embedded Report thru Web Link is not working

    I have a weblink with the following code https://secure-ausomxbsa.crmondemand.com/OnDemand/user/ReportIFrameView?SAWDetailViewURL=saw.dll?Go%26Path%3D%252fshared%252fCompany_30019_Shared_Folder%252fManagement%2bReports%252fOpportunities%2bBy%2bAccoun

  • Missing MSI files SQL Server 2008 R2 SP3

    I have hit an issue while installing Service Pack 3 for SQL Server 2008 R2. The existing version is 10.50.4295.0 (SP2+CU9)  When running the SP3 file the following error occurs SQL Server Setup has encountered the following error: The cached MSI file

  • ACE 4710 upgrade to A4(2.1)

    Hi, I am currenlty running A3(2.6) and evaluate the possibility of upgrading to A4(2.1). The Instal & Upgrade Guide A4(2.0) mentions that A4(2.0) does not include all features of A4(1.1). Does this apply to A4(2.1)? The Release Notes mentions a list

  • HTTPService POST sends header and body separately

    I'm having a performance issue with XML-RPC via the HTTPService component. The HTTPService.send() sends the request in two parts: first the headers, then the body. Evidently, the server get the headers, times out, sends an ACK, and then HTTPService s

  • Legal consolidation reset values

    Hi All My legal consolidation package behaves strangely. I input my data for consolidation on COM_RAW datascr which has is_CONSOL to Y and DATASCR_TYPE to I. In my businnes rules I used COM_RAW as source datascr and ELIM1 as destination datasrc which