• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

criteria format in criteriaFind method

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark,you mean that String "ori=SFO,des=SFO" is ok?
need no single quotes?
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the user search for blank combos or text fields then all the records will be return...
Regards
 
ragsulid
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
It is no measure of health to be well adjusted to a profoundly sick society. -Krishnamurti Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic