Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

loop trouble

 
Anand Shrivastava
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • 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.
 
Bob Ruth
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look up the difference between "==" and ".equals()".
 
Manuel Leiria
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
sorry, need not answer, i understood
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic