Select chunk at a time


EJB programming & troubleshooting: Select chunk at a time

  1. Select chunk at a time (1 messages)

    We are writing a web based system in EJB. One of the things I need to do is to let the user search the database. The result can be more then 1000 records. I would like to send a chunk at a time back to the user. How can I do that ?
    I have a stateless session bean that execute the query, and since it's a huge result I don't want to store everything in memory.

    Thanks in advance
  2. Select chunk at a time[ Go to top ]

    I have a similar problem. At the moment I have a stateful session bean that executes the query and stores the results. The client can then get these results back a few rows at a time using a getRows method and specifying the start row and number of rows. This way the client only holds what it needs. At the moment the session bean holds the whole result set which I need to find a way around as it may be very large.
    The system I am replacing used to just keep the cursor open and fetch rows back from the database as required. This is no longer possible as the session bean cannot keep a cursor open, and it's a bad idea anyway.
    We could have the session bean fetch back only say the first 100 rows of the query. If the client requested rows after that then the query would need to be re-executed to get the next block of rows. This may be ok if your query is fast. Also re-executing the query could cause problems if the data has changed causing a different number of rows to come back or the rows to come backin a different order.
    As you can see, unless you query is fast and the data does not change, this is not an easy problem to solve.