aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes UrlBird Primary Key In Regard to Jtable SelectedRow Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "UrlBird Primary Key In Regard to Jtable SelectedRow" Watch "UrlBird Primary Key In Regard to Jtable SelectedRow" New topic
Author

UrlBird Primary Key In Regard to Jtable SelectedRow

Jack Nam
Ranch Hand

Joined: Feb 09, 2010
Posts: 33
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

Joined: Jun 06, 2009
Posts: 221

Hi Jack,


Check this thread out.


HTH,


Carlos.


SCSA, OCA, SCJP 5.0, SCJD, CCDH, CCAH http://www.linkedin.com/in/carlosamorillo
Andy Jung
Ranch Hand

Joined: Feb 07, 2010
Posts: 150
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


SCJP, SCJD
Jack Nam
Ranch Hand

Joined: Feb 09, 2010
Posts: 33
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
Bartender

Joined: Jul 19, 2004
Posts: 5608
    
  15

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


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Jack Nam
Ranch Hand

Joined: Feb 09, 2010
Posts: 33
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
Bartender

Joined: Jul 19, 2004
Posts: 5608
    
  15

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
 
jQuery in Action, 2nd edition
 
subject: UrlBird Primary Key In Regard to Jtable SelectedRow