Meaningless Drivel is fun!*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes criteria format in criteriaFind 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 "criteria format in criteriaFind method" Watch "criteria format in criteriaFind method" New topic
Author

criteria format in criteriaFind method

Qusay Jaafar
Ranch Hand

Joined: May 06, 2002
Posts: 127
It is one of the moments when something is at the front of my eyes but I can't see it, so help me about it please. My question is related to criteria format which is:
"Origin airport='SFO',Destination airport='DEN'"
my question is:
what is the symbol before and after (SFO) which is (')? Why is it there?
If we use StringTokenizer for this criteria format so we can isolate the symbol (') or what?
thanks


Qusay
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

I didn't have mine have the single quotes in the value. And it worked fine.
The instructions.html had
Criteria take the form of a comma separated list of <field name>=<value to match> specifications.

there are no single quotes around the <value to match>
This sentence is a line or two above the sample you show.
Hope that clears things.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
If you're using jdk 1.4, you can just use a String.replaceAll() method to data strub out references to " and ' before the client sends it to the bank end.

M, author
The Sun Certified Java Developer Exam with J2SE 1.4


Java Regular Expressions
Marcos Motta
Ranch Hand

Joined: Apr 28, 2002
Posts: 56
Are you agreeing that criteriaFind() should work without quotes?
My criteriaFind() format requires the value to be enclosed in quotes. Furthermore, if the field name has blanks in the middle it must be quoted as well. For example:
'Origin Airport'='DEN', Carrier='XXX' //Ok
Origin Airport='DEN' // INVALID!
Your comments, please.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6


here's the line of code I had for adding the Origin airport criteria, as you can see I had no single quotes anywhere. It really doesn't matter. You can put the single quotes and use the replaceAll method that Max mentioned, or don't have single quotes. I didn't lose any points because of missing single quotes.
Mark
xin dong
Ranch Hand

Joined: Mar 24, 2003
Posts: 33
Mark,you mean that String "ori=SFO,des=SFO" is ok?
need no single quotes?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

No, it still needs the entire name of the field. You will need this when you try to find matches.
And you do not need single quotes.
Mark
Qusay Jaafar
Ranch Hand

Joined: May 06, 2002
Posts: 127
thank you for your reply. The lines in my instruction are same of yours. It is:
(Criteria take the form of a comma separated list of <field name>=<value to match> specifications.)
But the example below of these lines states:
("Carrier='SpeedyAir',Origin='SFO'") and that's what confuse me. Anyway, you make it clear.
my criteria is:
criteria = getField("Origin airport") + "="
+ selectedOrigin +
+ getField("Destination airport") + "="
+ selectedDestination;
private String getField(String fieldName) {
//loop through the fields
//if (fields[i].equals(fieldName)) {
// return fields[i]
//} else {
return "";
}
}// end getField() method
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

getField("Origin airport")

Your getField method only returns what you are passing to it. There is no need for this method.
Since "Origin Airport" is already the correct field name then why double check. The field name will not be entered by the user, and it is in your code. So just make sure you use the correct field name and then you won't need such a method like getField().

Mark
Mark
Qusay Jaafar
Ranch Hand

Joined: May 06, 2002
Posts: 127
Now, criteria = "Origin airport=" + selectedOrigin + "," +
"Destination airport=" + selectedDestination;
The user can select the desired items from Origin and Destination Combo boxes.
I am with you mark, but according to some search within the previous messages somebodies were talking about a generic criteriaFind() method.
What about the instruction? It mentioned (In the event of an invalid field name being provided as part of the criteria the behavior of this method is the same as if no records matched correctly specified criteria.)
don't you think the field names need to be checked?
Poorna Lakki
Greenhorn

Joined: Mar 04, 2003
Posts: 11
Hi guys,
In my criteria find method i specifically check for single quotes around the value in the key-value pairs using a regular expression. Does this mean i have to change it to support no single quotes around the value pair. If yes then the one thing I have to do is to use String.replaceAll() method as Max is suggesting.
Thanks,-Poorna Lakki
ragsulid
Greenhorn

Joined: Mar 27, 2003
Posts: 5
Hi,
I'd like to know if the user does a search with no input text, i.e. Origin=<blank> and Dest=<blank>, should I assume that its looking for all flights and display all the records in the database? Thanks for your help.
Rommel
Poorna Lakki
Greenhorn

Joined: Mar 04, 2003
Posts: 11
Originally posted by Rommel Agsulid:
Hi,
I'd like to know if the user does a search with no input text, i.e. Origin=<blank> and Dest=<blank>, should I assume that its looking for all flights and display all the records in the database? Thanks for your help.
Rommel

Rommel,
In my implementation i present the user with non-editable combo boxes for origin airport, destination airport and will construct the search criteria string based on the user selection. So, there will be no chance of user entering blanks. If u do it this way u donot have to assume blanks for all flights in the database.
Thanks,-Poorna Lakki
Qusay Jaafar
Ranch Hand

Joined: May 06, 2002
Posts: 127
If the user search for blank combos or text fields then all the records will be return...
Regards
ragsulid
Greenhorn

Joined: Mar 27, 2003
Posts: 5
Originally posted by Poorna Lakki:

Rommel,
In my implementation i present the user with non-editable combo boxes for origin airport, destination airport and will construct the search criteria string based on the user selection. So, there will be no chance of user entering blanks. If u do it this way u donot have to assume blanks for all flights in the database.
Thanks,-Poorna Lakki


Thanks Poorna,
Just wondering, did you use combo boxes for just the origin and destination fields? From the requirements, it looks like other criteria fields need to implemented as well, as part of the search, i guess based on user preference... but i'm wondering if the origin and destination fields are combo boxes, what about the other search criteria fields? Should they be combo boxes as well or just text fields. Thanks.
Rommel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: criteria format in criteriaFind method