title: How to resolve Out of memory if your procudure returns large number of records
body: <p>I am currently working on a Java application. The database used is Sybase ASE 15.0. Currently I am getting the following error in one of the scenarios:</p>
  
  <blockquote>
    <p><code>java.lang.OutOfMemoryError: Java heap space</code></p>
  </blockquote>
  
  <p>I have the following procedure call in my code:</p>
  
  <pre><code>CallableStatement cStmt = null;
  ResultSet rs = null;
  ArrayList list = new ArrayList();
  Connection con = getConnection();
  cStmt = con.prepareCall("call &lt;proc-name&gt;(?,?)", ResultSet.TYPE_SCROLL_INSENSITIVE,
  ResultSet.CONCUR_READ_ONLY);
  boolean b;
  // .....
  // .....
  while(rs.next()){
    List dList = new ArrayList();
    T t = new T();
    t.setProp1(rs.getBoolean("isAvailable"));
    t.setProp2(rs.getString("Name"));
    t.setDList(dList);
    ....
    ....
    t.setPropN(rs.getString("Property-name"));//many properties are read
    //  from db and POJO is populated.
  
  
    b = true;
    int Id = rs.getInt("Id");
  
    do{
       D d = new D();
       d.setProp1(rs.getFloat("&lt;property-name"));
       ....
       ....
       d.setPropN(rs.getString("Property-name"));//many properties are read      
       dList.add(d);
  
       if(rs.next()){
  
           if(rs.getInt("Id")!=Id){
                b = false;
                rs.previous();    
           }
  
       } else {
               b = false;
               rs.previous();
       }
    } while (b);
  
    list.add(t);
  }
  </code></pre>
  
  <p>The procedure receives date range as its arguments. If the date range is large, it returns large number of records. For small number of records, it is working fine, but for large records, it is giving 'out of memory' exception. I observed that if number of records is larger than 11997, then it gives this error.</p>
  
  <p>I read that simple resultset stores records in heap memory, but it should work with scrollable resultset, right? </p>
  
  <p>How do I remove this exception in this case.</p>