• 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

How to retrieve data from database every 10 minutes?

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I made swing application to display data from database (MySQL), but i can't figure it out how to keep the latest data that will be displayed if there new data on database.. should i use timer? and how?
Here is my code..


thanks.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ramses(!)
Welcome to the Ranch.

Check out http://oreilly.com/java/archive/quartz.html on how to use the Timer and TimerTask to schedule your tasks.
 
Ramses Butarbutar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maneesh Godbole wrote:Hi Ramses(!)
Welcome to the Ranch.

Check out http://oreilly.com/java/archive/quartz.html on how to use the Timer and TimerTask to schedule your tasks.



Thanks Maneesh.. but i still confuse implement it in my code.. Can you help to guide me to understand?
Here is my code to retrive data from db.


Should i initiate timer before getting the result or what..?
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you go through the Timer API Documentation?
Essentially you need to start the timer, to get it working. When to start the timer, would depend on your requirement. I would suggest, display the current data on the UI and once it is showing , start the timer, so its refreshed every 10 minutes or whatever time interval is specified.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When the Timer fires you create a new TableModel with the updated data. Then you replace the existing model in the table using the setModel(...) method of JTable.
 
Ramses Butarbutar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Camick wrote:When the Timer fires you create a new TableModel with the updated data. Then you replace the existing model in the table using the setModel(...) method of JTable.



Hahaha... Thanks alot Rob.. Yeah.. i missed that point... It's work now...
Here is the result
 
On top of spaghetti all covered in cheese, there was this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic