aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to retrieve data from database every 10 minutes? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to retrieve data from database every 10 minutes?" Watch "How to retrieve data from database every 10 minutes?" New topic
Author

How to retrieve data from database every 10 minutes?

Ramses Butarbutar
Ranch Hand

Joined: Jun 16, 2009
Posts: 52
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.


At the center of non-violence stands the principle of love
.... Martin Luther King, Jr.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Ramses Butarbutar
Ranch Hand

Joined: Jun 16, 2009
Posts: 52
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

Joined: Jul 26, 2007
Posts: 10451
    
    8

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

Joined: Jun 13, 2009
Posts: 2203
    
    7
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

Joined: Jun 16, 2009
Posts: 52
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to retrieve data from database every 10 minutes?