Win a copy of Mastering Non-Functional Requirements this week in the Design forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Bilal zafar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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 :


 
Campbell Ritchie
Sheriff
Posts: 54475
150
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Brian Cole
Author
Ranch Hand
Posts: 938
1
  • Mark post as helpful
  • send pies
  • 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.)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!