Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

How do I implement pagination in JDBC?

 
Ranch Hand
Posts: 172
2
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Best, Mr. Snortum!

I have solved this today! I used a static variable called pageNum which is my page variable. Now the method that takes care of the JComboBox event looks like this



But anyway, you were right. The error had to do with pageNum that did'nt decrement properly after a JComboBox event. I have managed to paginate both backward and forward now between pages of 10 records. I am pleased with the result  

Best wishes,
Robert!

 
Sheriff
Posts: 7108
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's great!  Glad I could be of service.
 
Robert Ingmarsson
Ranch Hand
Posts: 172
2
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe this thread is now solved

//Robert
 
Saloon Keeper
Posts: 22097
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hate to say this, but this whole approach is over-complicated. Maintaining a GUI Table Model based on a slice of a SQL query is only a moderately-difficult problem. Its essence it this:

1. You have two maintenance values: the current row number ("X") and the number of rows to pull into the table ("N").

2. When you wish to initially fill or page the table, you discard the model's current row collection, do the query and tell it to return starting with row "X" and returning "N" nows. Read those rows and build Model row objects which are then added to the table. Once the table model is updated, you can refresh its display (in desktop UI's that's "invalidate" the UI element(s) in question).

3. To page forwards, increment "X" by adding "N" to it to get the new "X", then repeat step 2. To page backwards, subtract "N" from "X", and if the result is less than 1, set "X" to 1, since there are no zero or negative rows.

Other considerations: the last page of the SQL results may contain less than "N" rows. That's fine, but you get extra points for setting an indicator that "X" cannot be incremented further. That may include disabling the "forward" button. Likewise, when "X" is less than "N", disable the page-back button.

And remember, each time you execute Step 2, you are doing a brand new query. If any of the underlying rows of the query have been modified or if rows have been inserted and/or deleted, it can affect the repeatability of the results being displayed. Therefore you should only attempt to page data sets that you know will not be altered while they are being viewed.
 
Yeast devil! Back to the oven that baked you! And take this tiny ad too:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic