1

I am querying the history table having millions of records using java swing. So it takes 20 mins to complete the job. Until that I need to display jProgressBar or something to show the user that query is still running. How to do that? Also how to find the max number to progress bar? Since it has million rows I cannot use total row count to do it. Please asvise. Also suggest anyother option other than jProgressbar also.

thebluephantom
  • 16,458
  • 8
  • 40
  • 83

1 Answers1

0

Rather than fetching all the records at a time fetch the data in chunks.

Now increment the progress bar once a chuck of data is received in the proposition of the chuck size and total no of records.

Fetching all the data in single transaction is not a good way if no of records are in millions. Sometime it results into OutOfMemoryError and Transaction TimedOut.

If possible then design your application to show data in pagination that is more efficient and will not take 20 minutes to make end user happy.


Please have a look at below link to get it done:

Sample query for reading data in chunks just like pagination:

select * 
  from (select q.*, rownum rnum
       from ( [your query goes here] ) q
      where rownum <= chunk_number * chunk_size )
  where rnum >= ( chunk_number -1) * chunk_size + 1
Community
  • 1
  • 1
Braj
  • 46,415
  • 5
  • 60
  • 76
  • How to get the values like that. I havent heard of that before. – user2892124 May 10 '14 at 13:19
  • how are you fetching the data from database? – Braj May 10 '14 at 13:19
  • Something like just using normal query. Select name, id from employee_his; then write each record to an array and pass it to another method to write that as excel. – user2892124 May 10 '14 at 13:21
  • I have shared a link in my post. – Braj May 10 '14 at 13:22
  • This is ok but still I am wonder how progress bar knows max value and shows correct progress.. – user2892124 May 10 '14 at 13:32
  • First get the total no of records let's suppose it is 1000. and chunk (page) size is 100 then just increment the progress bar by 10% for each chunk. – Braj May 10 '14 at 13:34
  • or you can do in this way also set `JProgressBar jbar = new JProgressBar(0,1000);` and call `jbar.setValue(100)` for each data arrival. here min=0 and max=1000. – Braj May 10 '14 at 13:35
  • I am afraid to get row count since even that takes 3 mins min.. So that would delay my operation that 3 mins more.. – user2892124 May 10 '14 at 13:37
  • That's I suggest you to use pagination in your application as mentioned in my post as well to make your end user happy that will take less than 1 minutes I guess because there is no meaning of fetching all the records at a time. – Braj May 10 '14 at 13:39