2 messages in com.mysql.lists.javaRe: Problem Testing Conditions within...
FromSent OnAttachments
Mark Matthews08 Mar 2000 17:03 
Stuart G. Poss08 Mar 2000 17:12 
Subject:Re: Problem Testing Conditions within ResultSet Loop. Suggestions?
From:Mark Matthews (mmat@worldserver.com)
Date:03/08/2000 05:03:28 PM
List:com.mysql.lists.java

use .equals() instead of ==. The .equals() method of Object compares object for similarity (i.e. "abcd" is the same as "abcd"), == compares references is this the object the _exact_ same (as in instance) of the other object.

-Mark (author of MM.MySQL)

On Wed, 8 Mar 2000, Stuart G. Poss wrote:

I have a simple database in which I am attempting to iterate through a ResultSet and conditionally print column cells depending upon the values in a previous row (I want all the url's and names to print without printing the url_owners, if the current url_owner is the same as the previous url_owner).

I have created the following snippet of code, but the test ALWAYS returns false as I iterate through the ResultSet, even though the values of some consecutive url_owners in the ResultSet ARE identical.

Any suggestions as to why the following conditional test fails to perform according to my expectation?

I'm using the mm.mysql driver version 1.2b and mySQL V3.22.30.

String query = "select url_name, url, url_descrip, url_owner_organ from immunology order by url_owner_organ"; ... ... ....

owner_last=""; while (rs.next()) { String name = rs.getString("url_name"); String url = rs.getString("url"); String owner = rs.getString("url_owner_organ");

/*TEST IF OWNER IS SAME AS LAST OWNER*/ if (owner == owner_last) { out.println("<DL><UL><LI><A HREF=\"" + url + "\">" + name + "</A></LI></UL></DL></BR>"); } else { out.println("<DL><B>" + owner + "</B><BR><UL><LI><A HREF=\"" + url + "\">" + name + "</A></LI></UL></DL></BR>"); } owner_last = owner; } out.println("</UL>");

To unsubscribe, send a message to the address shown in the List-Unsubscribe header of this message. If you cannot see it, e-mail java@lists.mysql.com instead.