1

Is there a way by which JTable auto-updates itself, by including some timers or related stuff into our coding? There may be times when i update my database(back-end) from somewhere else, so is that possible that JTable auto-updates itself when it encounters certain changes in the database??

2 Answers 2

1

possible that JTable auto-updates itself when it encounters certain changes in the database??

  • yes, for Oracle and MySql there are a 3rd party libraries, workaround that returns desired events from DB interpreter, that will notify about changes in Database

Is there a way by which JTable auto-updates itself

There may be times when i update my database(back-end) from somewhere else,

  • yes, is possible to start Timer and on some bases to check tables for changes (see that as better way as to use 3rd. party libraries) and on some /the same bases to update the XxxTableModel

  • all changes for Swing GUI must be done on EventDispatchThread, more in Concurency in Swing

3
  • why a timer? Not needed if the database notifies about its changes: simply update the tableMode when receiving such a notification and be happy :-)
    – kleopatra
    Oct 3, 2012 at 9:31
  • @kleopatra not all "notifiers" are free_for_use :-), easiest of the ways is triggering inside DB interpreter and to check about possible change from outside, depends of project / homework / e.i.
    – mKorbel
    Oct 3, 2012 at 9:37
  • ahh ... thanks. You might consider to edit your answer with that (aka: polling as last resort as there is no means to receive a a notification from the db directly :-)
    – kleopatra
    Oct 3, 2012 at 9:41
-1

Whenever there is a change in DB set a param value. On the JTable handler code, use SwingTimer to fire after every certain period of time. In the timer code check the DB param value. If it is set, read your database, prepare your new Table Model object, then set it on JTable. And then fire modelchange event.

3
  • ok cool, will try out...have to keep in mind the new result doesn't add up with the previous results...have to over-ride the new result with the earlier one
    – user1711524
    Oct 3, 2012 at 7:22
  • 1
    You shouldn't connect to the database in your 'Timer code' as that code will be executed on the EDT. Connecting to the database should happen on a worker/background thread. Further, if you set a new model on the table, there is no need to fire a model change event.
    – Robin
    Oct 3, 2012 at 7:53
  • @Robin ohkay thanks...do you have any reference material for the same? (other than oracle docs)
    – user1711524
    Oct 3, 2012 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.