• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Parsing the String

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public DataInfo[] criteriaFind( String criteria ) throws
DatabaseException {
int numberOne = 1;
int numberTwo = 2;
int aIndex, bIndex;
String first, second, firstField, secondField;
aIndex = criteria.indexOf( '=' );
firstField = criteria.substring( 0, aIndex );
bIndex = criteria.indexOf( ',' );
first = criteria.substring( aIndex + numberTwo,
bIndex - numberOne );
aIndex = criteria.lastIndexOf( '=' );
secondField = criteria.substring( bIndex + numberOne,
aIndex );
bIndex = criteria.length();
second = criteria.substring( aIndex + numberTwo,
bIndex - numberOne );
}
Strings first & second represent the values in the Query Column and
Strings first field & second field represent the field names.
Is this parsing Okay,
Or is there a better way to do it?

Thanks for any reply.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sure you can do it better then this. The current implementation you have created is not a generalized and is more specific to a criteria which is here
�Column Name = �value�, Column name=�value��.
The current implementation is limited to two columns. What if a user wants to search a record with more then two columns or with only one column? I.e
Criteria string
Column name=�value�,Column name=�value�, Column Name=�value�
Or The Criteria string is
Column name =�value�.

A tip
Use string tokenizer (StringTokenizer) and hash table(Hashtable) class to parse and hold the column name and value pairs.
Then compare it with the Database record column values.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic