This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

UrlBird Primary Key In Regard to Jtable SelectedRow

 
Jack Nam
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everybody,

With the assumption that the String data[] only contains DB Schema excluding recNo, I am wondering how would you get the recNo of the Jtable SelectedRow for booking since there is no primary key?

Is it a wrong assumption?

Please advice. Thanks in advance.
 
Carlos Morillo
Ranch Hand
Posts: 221
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jack,


Check this thread out.


HTH,


Carlos.
 
Andy Jung
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jack,

1. I just included the primary key, i.e. the record number, to the String[] data declared by DB's interface.
Is this assumption valid anyway?

2. I didn't implement the GUI with the JTable yet, but my idea is to set the recNo in a hidden column of the JTable to retrieve it again, when requesting a row for modification on server.
Is this approach to hide a column possible with a JTree?

Kind regards,
Andy
 
Jack Nam
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy Jung wrote:Hi Jack,

1. I just included the primary key, i.e. the record number, to the String[] data declared by DB's interface.
Is this assumption valid anyway?

2. I didn't implement the GUI with the JTable yet, but my idea is to set the recNo in a hidden column of the JTable to retrieve it again, when requesting a row for modification on server.
Is this approach to hide a column possible with a JTree?

Kind regards,
Andy


Hi Andy,

I believe you must utilize this method.


Pass the rec no to the upper layer.

 
Roel De Nijs
Sheriff
Posts: 9933
113
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy Jung wrote:Is this assumption valid anyway?
It is a valid assumption, but it is certainly not the best possible approach. And don't forget to be consistent in that approach: so every String[] should have the primary key included, otherwise code maintenance will be hard (certainly if another developer has to make the changes to your code).

Is this approach to hide a column possible with a JTree?
Why do you want to use a JTree? Or is it just a typo and did you mean JTable? Anyway you don't have to hide a column. You can keep track of the recNo without having to show it. The thread mentioned by Carlos Morillo contains a lot of valuable information about how to populate your JTable.

Jack Nam wrote:I believe you must utilize this method.
That is not a requirement. You must have an implementation for that method, but you don't have to use it. I created my own find-method which returns a Map<Integer, String[]> and I used that one instead of the other one.

Kind regards,
Roel
 
Jack Nam
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:That is not a requirement. You must have an implementation for that method, but you don't have to use it. I created my own find-method which returns a Map<Integer, String[]> and I used that one instead of the other one.

Kind regards,
Roel



I thought you must utilize the findByCriteria of the DBAccess as it is the DB interface you must use and you are not allowed to alter the interface.

And I plan to put the recNo as pk of the model object instead of using the map. It just feels right.
 
Roel De Nijs
Sheriff
Posts: 9933
113
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jack Nam wrote:I thought you must utilize the findByCriteria of the DBAccess as it is the DB interface you must use and you are not allowed to alter the interface.
You must not alter the interface, that's true. But you can simply create your own interface, which extends from Sun's interface and you won't break any must requirement. Because that's what I did (and many others).

I used the map for convenience. When you do a find, you get an array of record numbers. To show the records you have to do seperate reads for every record number in the returned array. But between find and these reads a record can be deleted. So you have to handle a RNFE, with a find-method which returns record numbers and the appropriate records it is not needed.

Kind regards,
Roel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic