• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Show large resultset from database into jtable with scroll pagination in java swing

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
I am very new to java, so please ignore if you think this question is stupid. A task has been assigned to me in which I have to extract data from h2 database table with **more than 1 crore rows (SAD) from one table.** And finally show that data into a j table with pagination.
What i exactly want is that when the program starts, it extract lets say 1 lac record from database and when user scroll down to the end of first lac records and again extract another lac data from database and so on …
It will be best if he goes scroll up, the program doesn’t extract rows which are already extracted. I Hope I explained my problem here very well.
Now, After a lot of googling, I found this  (https://coderanch.com/t/345383/java/JTable-Paging)very good article which does 90% of what I want, but not with database connection. Can any one tell how to do this ?
Here is the sample code :


 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

No, it isn't a stupid question (though I don't know enough about tables to answer it).
There is something peculiar about the method to get column names; why can't you create an array? Or better still, get metadata from the database itself? Yes, ResultSet has a getMetaData method and that allows you to get a column title with the column label or column name or similar methods.

It would appear that part of the problem is how to read 1,000,000 (=10⁶) records out of a larger database (I thought a lac was 100,000=10⁵). I'll try duplicating this discussion in the databases forum in the hope of getting better attention there. I presume you cannot read a crore (??10⁷??) records at once without overwhelming the available memory capacity.
 
Bilal zafar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, for now, There is no database connection in my code, So that's why I get column like this. And yes, when I will do it with database I will try to get Column name from database as well or I will make an array to handle column names. Well, 10⁶ or 10⁷ doesn't matters. In future the records can be more than this also. And yes, I need to show all data from this.
For this, I need two things. Optimized query to extract data and then use pagination to show that optimized data.

Thanks for the reply, Let me know if you have any input for me
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Replace Thread.sleep() on line 62 with your database query. The only reason it's calling sleep() there is to simulate network latency. There probably shouldn't be any sleep()ing in your final code.

Then in lines 68-71 you need to fill page with data from your query, instead of just pretending that the results are the same as the row numbers.

BTW this is my code. (Looking back on it, I should probably have made some changes to make it easier to understand. For example, the SortedSet<Segment> isn't doing anything tricky, but it's kind of hard to tell the way I wrote it.)
 
reply
    Bookmark Topic Watch Topic
  • New Topic