The moose likes Developer Certification (SCJD/OCMJD) and the fly likes String to be passed to the criteria Find method Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Developer Certification (SCJD/OCMJD)
Reply Bookmark "String to be passed to the criteria Find method" Watch "String to be passed to the criteria Find method" New topic
Author

String to be passed to the criteria Find method

poornima sudharshan
Greenhorn

Joined: May 18, 2001
Posts: 18
This piece of code constructs the String which is passed to the
criteria find method.I would like to know whether this is
appropriate.
/** I have used 2 constants to get the corresponding column name from
the database */
public static final int SEARCH_FIELD_FIRST_INDEX = 1;
public static final int SEARCH_FIELD_SECOND_INDEX = 2;
FieldInfo[] schema;
FieldInfo info;
String fieldOne, fieldTwo;
schema = dbFile.getFieldInfo();
info = schema[ SEARCH_FIELD_FIRST_INDEX ];
fieldOne = info.getName();
info = schema[ SEARCH_FIELD_SECOND_INDEX ];
fieldTwo = info.getName();
/** Here I do the concatenation */
String toFind = fieldOne + "=" + "'" + (String)listOrg
.getSelectedItem() + "'" + "," + fieldTwo
+ "=" + "'" +
(String)listDes.getSelectedItem() + "'";
dbFile.criteriaFind( toFind );
This string goes to the criteria find method of the Data class.
I thought if the application is modified later & some other search
criteria is used,
then all they have to do is to change the constants.
Is this construction of the String correct?
plz reply.
poornima.
Vivek Viswanathan
Ranch Hand

Joined: Mar 03, 2001
Posts: 350
Hi
Probally you could shift the constants to an interface, and declare the constants as
public static final
and use this constans in your program as
interfaceName.CONSTANT_NAME
that will be a better desing, as it will allow for a more gracefull change.
Actually that is what I did.
Vivek Viswanathan

[This message has been edited by Vivek Viswanathan (edited June 19, 2001).]


Vivek Viswanathan SCJP 1.2, SCJP 1.6,SCJD,SCEA,SCWCD,IBM-484,IBM-486,IBM-141,Ms.NET C# 70-316,SCMAD, LPIC-I
 
 
subject: String to be passed to the criteria Find method
 
Threads others viewed
Two methods into one
criteria string
DataInfo[] criteriaFind(String criteria);
Servlet condition block moved to Helper class
question about assignment
developer file tools