• 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

How to construct 'String criteria' ? Help!!!

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everybody,
Following are the lines from requirements
/* Start here*/
public DataInfo[] criteriaFind(String criteria)
This method searches the database for entries matching the criteria supplied. Criteria take the form of a comma separated list of <field name>=<value to match> specifications. For example, the following argument string would select all records describing flights by the SpeedyAir carrier that originate in San Francisco. "Carrier='SpeedyAir',Origin='SFO'" /*Line A*/
/*ends here*/
I got stuck with construction of String criteria. As per my understanding, once I get values of Origin and destination airports from JComboBoxes, then I have to convert that values into String criteria = "Origin airport='SFO',Destination airport='Bom' ". And pass this String to public DataInfo[] criteriaFind(Strring criteria).
For costructing this String criteria in the format given by line A, I have used follwoing method
/* following is a Search class to populate the values from Database and construct the String criteria
public class Search extends JFrame implements ActionListener{
....
...
...
jlb1 = new JLabel("Origin airport");
jlb2 = new JLabel("Destination airport");
jcb1 = new JComboBox(fbn.getFlight());
jcb2 = new JComboBox(fbn.getFlight());
jb1 = new JButton("Search");
jb2 = new JButton("Clear");
/* all these components are added in a Panel using GridBgaLayout and added actionListener to "search" and "Clear" Buttons*/
public void actionPerformed(ActionEvent event){
Object source = event.getSource();
if(source == jb1){
sb = (jlb1.getText()+"='"+jcb1.getSelectedItem() +"',"+jlb2.getText()+"='" +jcb2.getSelectedItem()+"'");...................Line B
/* String sb is then passed to criteriaFind() method.
}
Question 1: So my Line B constructs String into form "Origin airport='SFO', Destination airport='Bom'" . Is this a correct way of doing it? Or I am going in wrong direction? Any hint to construct the String is appreciated.
Question 2: I am constructing String critaria as "Origin airport='SFO', Destination airport='Bom'" and not as
[b]"Origin='SFO', Destination='Bom'"[b] given as per SUN requirements. Because my criteriaFind() methos needs complete name of fields to passed. So that it compares with database fieldnames. I will document in my Design documnet all this stuff.
Is this O.K.? Or the marks will be reduced.
Thanks
Pratibha

 
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
Well, from my perspective, it looks good. The only thing I did differently was to use a StringBuffer, and also to create a class that makes criteria strings for me, but in the same manner as you did.
Mark
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well Prathiba,
In short it looks fine. However some suggestions if you will consider. The origin city and destinatin city can be created as constants in the class and be used them in the creation of String.
One question : How are you passing this String to criteriaFind method ?
 
Raju, Gentle
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you briefly explain how you are implementing your UI ?
 
Pratibha Gayake
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am still looking for answer for Question 2,
Question 2: I am constructing String critaria as "Origin airport='SFO', Destination airport='Bom'" and not as
[b]"Origin='SFO', Destination='Bom'"[b] given as per SUN requirements. Because my criteriaFind() methos needs complete name of fields to passed. So that it compares with database fieldnames. I will document in my Design documnet all this stuff.
Is this O.K.? Or the marks will be reduced.
 
Pratibha Gayake
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Marks for your earlier reply.
Hello Raju,
I am approaching my GUI as per following,
Part 1:
1.I designed one single Panel with gridbaglayout, components like JComboBoxes, JLables and Buttons for "Search" and "Clear" are added.
2. Method getFlight() fills the Origin and Destination JComboBoxes from Database.
3. I first tried to display all above stuff. I still have not handled event handling upto this point.

Part 2:
I created a JTable by using MVC pattern.
Model - MainTable , which holds data of Databse and has getter and setter methods for columnNames and rows(rows of DataInfo)
Controller - Uses Setter method of mainTable. This class has criteriaFind("Origin airport='SFO'") method.(This criteria is not from JCoboBoxes, it is a fake criteria , just to test whether my JTable is created with this criteria.) The result of criteriaFind is used to set the values in MainTable.
FbnTableModel- This class extends AbstractTableModel and implements getRowCount(), getColumnCount,getValueAT() method. These methods basically use getter methods from MainTable.
Finally View - extends JTable and dispalys the Jtable.
My Part 1 and Part2 are not still linked. Means whatever criteria I selected in part 1 is not passed to Part 2 to display JTable. I just divided GUI in two parts so that I can write, test the code separately. Now I am sure for functinality of both.
Now I am going to combine the two parts. I have formed the String criteria from Comboboxes. And I am working to pass this String criteria, from part 1 to Part 2, to dispaly the JTable.
Hope it helps
Pratibha
 
Raju, Gentle
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it is fine to proceed the way you are preceding. The reason I do not see anything like [b]"Origin='SFO', Destination='Bom'"[b] in the requirement, at least the one that I a have received.
Regarding the GUI layout, I am stuck with the event handling.
In brief I have created an Input Panel and this will consists of all the combo boxes and Search button. Also I have table and table model. Latter I will have to place these two together. The problem here is how to write an event handling for these two. I know MVC approach will help me in getting good marks as well as opportunity to learn MVC. So I am rather working to come up with model (s), views, Controller. But so far not successful. I will read your post in detail latter and post my questions or queries latter.

[This message has been edited by Raju, Gentle (edited October 12, 2001).]
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The sun requirement says
The user should be able to select the origin and destination of flights, and the display should update to show only flights that satisfy those criteria. The user must be able to describe enter the string value "any" for the origin, destination, or both, so as to implement a wildcard-like feature.
I am in bit confusion with above spec. I divided above with 2 points
1. The user should be able to select the origin and destination of flights
2. The user must be able to describe enter the string value "any" for the origin, destination, or both, so as to implement a wildcard-like feature.
From the point(1), I am thinking of using combo boxes for selecting Origination & Destination Airport locations.
If I use the JCombo boxes how can I do the point(2) i.e how can the user enter "any" or "wildcard-like feature".
Since I am thinking of filling the Jcomboboxes directly from the "db" data, I am in confusion with this requirement.
I appreciate if somebody can clarify the above requirement. Probably I may be interpreting wrong.
Thanks
Jyothi

[This message has been edited by jyothi ve (edited October 12, 2001).]
 
Pratibha Gayake
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You must be filling your JComboBox from Database using Vector or Array. Then first add "ANY" to the Vector and fill the remaining from db.db. So in GUI you will display first "ANY" then reamining "ABQ" ,"ATL" and .....stuff.
Is it clear.
Pratibha
 
jyothi ve
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mean to say that need to have different implementation for finding the orig/Dest Airport match with "any" one and with "SFO, LAX etc" selection another one.
Jyothi
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All of you
According to my spec. Sun is asking for the string in the criteriaFind() method
is like this "Origin='SFO',Destination='BOM'" Which should be enter into
a single JTextField and there will be a Search Button as well as Clear Button.The
String will be seperated with the help of StringTokenizer and passed into a Vector.
This Vector will furthur used in our FlyTableModel class which extends Abstract Table
Model class.According to me there is no use of JComboBox in our GUI regarding the
Flight Search.This makes our searchCriteria() Method generic.I have done this,
If there are some other ideas plz let me Know.
Anurag Mishra
 
Yup, yup, yup. 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