• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

DataInfo getValues() problem- see code

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This piece of code got me stumped for a whole day and I can't figure out why:
public class Project {

public static void main(String[] args) {
try {
Data x = new Data("c:\\temp\\scjd\\starting\\suncertify\\db\\db.db");

DataInfo[] r = x.criteriaFind("Origin airport='SFO',Destination airport='*'");

String [] values = r[1].getValues();
System.out.println(values[8]); // this prints out 22
if (values[8].equals("22"))
System.out.println("22");
else
System.out.println("not 22");

x.close();
} catch(DatabaseException ex) {
System.out.println(ex.toString());
} catch(IOException ex) {
System.out.println(ex.toString());
}
}
}

For some reason, it always prints out "not 22". Any input would be appreciated. Thanks
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The value probably has trailing spaces on it... Remember, this is a PRIMITIVE database - all coluumns are fixed width.
Try:
values[8].trim().equals...
 
Justin Wong
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just tried it and it works! Thanks a million.
 
Why should I lose weight? They make bigger overalls. And they sure don't make overalls for tiny ads:
ScroogeXHTML 8.7 - RTF to HTML5 and XHTML converter
https://coderanch.com/t/730700/ScroogeXHTML-RTF-HTML-XHTML-converter
    Bookmark Topic Watch Topic
  • New Topic