Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

synchronizing windows that view db table  RSS feed

 
Hugo Rabson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's say I create an SQL database, bind a JTable to it, edit a row in the table, and commit to the database. I would like a second window (which displays a specific row from that table) to reload the row from the database and display the new value, in case it changed with the recent commit.

I think this uses signals, events, listeners...

I'd like to grasp the concepts first. That's the most important thing. I can write the code if I can just understand how to solve the problem.

TIA,
Hugo
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a job for a transaction on the part of the update, then after the update is complete, call a refresh() method on the distant display.

Also sounds like something which would sit better on our JDBC forum, so I shall move you . . .
 
Paul Clapham
Sheriff
Posts: 22482
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it does involve listeners. Let me move this to the Swing forum where such listeners are normally discussed.

(I wouldn't expect the listener to have to go to the database when it is notified that the first table model has been changed. Actually I would expect that both JTables would have the same table model if possible.)
 
Hugo Rabson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If there is one SQL table, bound to two different JTables by BeansBindings and persisted by Hibernate + a session singleton (because sessions are not thread-safe), then I may change+commit changes to the table via jtable1 and send a refresh() to jtable2 to make sure it reflects the changes: is that correct?

Re: sharing a data model --- I'm still trying to grasp this concept. Is the data model like a matrix to which the raw data is mapped? If I create a single, shared data model for both JTables, does the fact that I'm using BeansBinding and persistence force me to create a table model class from scratch or will a DefaultTableModel(?) with extensions do?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!