GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes loop trouble Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "loop trouble" Watch "loop trouble" New topic
Author

loop trouble

Anand Shrivastava
Ranch Hand

Joined: Jul 22, 2007
Posts: 125
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.


Anand Shrivastava
SCJA
Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 320
Look up the difference between "==" and ".equals()".


------------------------
Bob
SCJP - 86% - June 11, 2009
Manuel Leiria
Ranch Hand

Joined: Jul 13, 2007
Posts: 171
When comparing string contents, don't use !=, instead use .equals,



Manuel Leiria<br /> <br />--------------<br />Peace cannot be kept by force; it can only be achieved by understanding. <br /> Albert Einstein
Anand Shrivastava
Ranch Hand

Joined: Jul 22, 2007
Posts: 125
but how will we compare not equals. there is no .notequals() class.
Anand Shrivastava
Ranch Hand

Joined: Jul 22, 2007
Posts: 125
sorry, need not answer, i understood
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: loop trouble