This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX:B&S Find Method 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 "NX:B&S Find Method" Watch "NX:B&S Find Method" New topic
Author

NX:B&S Find Method

Murali Kurukunda
Ranch Hand

Joined: Oct 20, 2003
Posts: 36
The long[] FindByCriteria[String[] criteria) returns the record numbers that match the criteria. I am in the process of implementing the server. When the client calls the search I want the server code to return of the records to the client. Is there a recommendation on how to do it? i.e Should there be a Record class that implements Serializable and should be used for the communication between client and server?
Thanks,
Murali
Jared Chapman
Ranch Hand

Joined: Feb 23, 2004
Posts: 81
Hi,

I have a different assignment than you, but that's basically what I did. The data class treats a record as a String[], which does not include the record number. So I made a serializable Record class that wraps a record and its record number. The search method in my DataAdapter class returns a Collection of matching Records.


B.S. University of Wisconsin<br />SCJP 1.4 (85%)<br />SCJD 1.4 (92%) B&S Contractors
Murali Kurukunda
Ranch Hand

Joined: Oct 20, 2003
Posts: 36
Thanks for the reply! Why do you need the record number inside the Record class? I am not sure whether I need to have the record number inside the Record class, I will decide once I implement the class. But is there a specific reason that I am missing?
jiju ka
Ranch Hand

Joined: Oct 12, 2004
Posts: 306
Jared is right.

Why do you need the record number inside the Record class?


The read(int i):String[] method returns an array of String. But after the read if we dont keep the int i value which is the record number there is no way we can figure which record this array belong to. This will be a problem if we want to update the record after reading.

You need to keep that association between record Number and data (Array of Strings) somewhere. A record object is ideal place to have it.

Thanks for the idea Jared.
Jared Chapman
Ranch Hand

Joined: Feb 23, 2004
Posts: 81
More specifically, consider what happens when you populate your JTable with the results of a search. The row number in a JTable is not an accurate indication of a record's record number.

For example, if you populate the JTable in your GUI with all the records in the database on startup, then the 4th record in the JTable should be the 4th record in the database. But what happens if you perform a search that only returns the 4th record in the database? In this case, the 4th record in the database is the 1st row in the JTable. If you then tried updating this record, you wouldn't actually be updating the 4th record in the database, but rather the 1st one.

That's why it is important to keep a record and it's record number together. The first column of my JTable is the record number, and since the actual record number isn't important to the user, I make this column invisible.

Hope this helped.
Murali Kurukunda
Ranch Hand

Joined: Oct 20, 2003
Posts: 36
This really helps..I am working on my network server design..Was just concentrating on the Search method..didn't this of bookRecord(). It makes perfect sense.
 
GeeCON Prague 2014
 
subject: NX:B&S Find Method