• 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

loop trouble

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear friends,

please see the following code ;

try {
aset.first();
String author_entered=jComboBox3.getSelectedItem().toString().trim();
while (aset.getString("authorname").trim()!=author_entered)
{aset.next();}
anand.jset("insert into public.subject (subject,aid) values ('"+jComboBox1.getSelectedItem()+"','"+aset.getString(1)+"'");}
catch (Exception E) {System.out.println(E.getMessage());}

THE WHILE Loop over here continues even after it finds exactly equal values of aset.getString("authorname") and author_entered. I have checked their lengths too. They are also the same. I dont understand why it keeps on doing next and reaches the end of resultset.

Please help.
 
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look up the difference between "==" and ".equals()".
 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When comparing string contents, don't use !=, instead use .equals,

 
Anand Shrivastava
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but how will we compare not equals. there is no .notequals() class.
 
Anand Shrivastava
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry, need not answer, i understood
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic