Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to retrieve data from database every 10 minutes?

 
Ramses Butarbutar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • 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.
 
Maneesh Godbole
Saloon Keeper
Posts: 11178
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
Saloon Keeper
Posts: 11178
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Camick
Ranch Hand
Posts: 2616
9
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic