aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Inserting Record Into JTable For An Specified Interval Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Inserting Record Into JTable For An Specified Interval" Watch "Inserting Record Into JTable For An Specified Interval" New topic
Author

Inserting Record Into JTable For An Specified Interval

Tanzy Akhtar
Ranch Hand

Joined: Jul 19, 2009
Posts: 110
Hi,

How to insert a new row into JTable at every interval of 5 minutes?
Also how to fix the maximum number of rows in the table? Let it be 50 as maximum number of rows are allowed. At the time of 51st row insertion, it should look for the row which was inserted earliest.

Scenario :

There is a table, "mytable" in database, with columns {createdTime, name, address}.
Now i want to display these data on swing UI based on JTable, which gets refreshed at interval of 5 minutes, i.e if there is insertion of any new in "mytable" during the 5 minute interval, then it should insert the same data into JTable.

Thanks.


Roll with punchers, there is always tomorrow.
Techie Blog -- http://jtanzy.blogspot.com/
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9

How to insert a new row into JTable at every interval of 5 minutes?

Check out javax.swing.Timer For more complicated scheduling scenarios google for "Quartz"

Also how to fix the maximum number of rows in the table? Let it be 50 as maximum number of rows are allowed. At the time of 51st row insertion, it should look for the row which was inserted earliest.

Since your data is coming from the DB, the easiest approach would be modify your DB query such that it picks out the latest 50 records based on insertion time or whatever your criteria is.


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

Joined: Jul 19, 2009
Posts: 110
Hi Maneesh,

I tried to implement the JTable. Created my own model by extending "AbstractDataModel" and defined essential method like getValueAt etc. Some methods i want to show :



and to populate data i used this :


And in main method calling in this way :


Now just only one data is being shown in JTable. Where am i doing mistake? Please point it out.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
tanzy akhtar wrote:Hi Maneesh,

I tried to implement the JTable. Created my own model by extending "AbstractDataModel" and defined essential method like getValueAt etc.


I've not heard of "AbstractDataModel" but perhaps you're referring to "AbstractTableModel". If the latter, please note that many of us have had good success using classes that extend DefaultTableModel where much of the model's functionality had already been built for you.

Tanzy Akhtar
Ranch Hand

Joined: Jul 19, 2009
Posts: 110
I've not heard of "AbstractDataModel" but perhaps you're referring to "AbstractTableModel".

Thank you for coreting me Pete.

Well, some people say that it would be better, if model class extends AbstractTableModel instead of DefaultTableModel.
Let me tell you my need. I need to fire a query, every ten minutes, to database for table "T",having column of type Date,Integer and String.
Now need to show this data on UI using JTable up to maximum 10 rows.
Now let me know your advice, whether it will good to follow DefaultTableModel or need to extend AbstractTableModel?

Thanks,
Tanzy.
mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
hi tanzy, you do not need to insert the same data in your jtable object. you only need to insert the data into your table model object

as someone mentioned awhile ago, you can use a Timer for that. or, create your own thread and have your jtable object reload its table model contents every 5 minutes


Website/Java Games: http://www.chitgoks.com
Tech Blog: http://tech.chitgoks.com
Tanzy Akhtar
Ranch Hand

Joined: Jul 19, 2009
Posts: 110
Thank you Mark, Pete and Maneesh for helping to resolve the problem.
 
Don't get me started about those stupid light bulbs.
 
subject: Inserting Record Into JTable For An Specified Interval