File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes to use == or equals on getString ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "to use == or equals on getString ?" Watch "to use == or equals on getString ?" New topic

to use == or equals on getString ?

Chris Davies
Ranch Hand

Joined: Feb 26, 2003
Posts: 110
i'm using the following code within a page

<c:resultSet id="rs" name="bean" type="java.sql.ResultSet"><webtop:column id="column" name="bean" fieldname="TERM_COLUMN">

condition='<%= !rs.getString()

in terms of using the rs.getString method do i have to use

== null or

rs.getString().equals null

if i want to test it prior to displaying it on the jsp page ?

also would i have to use the <c:else> tag after this then would the ocde know that if it didn't fulfill the ifthen condition then it shouldn't process ?



One day all greenhorns will run free ...
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Use == to test for a null reference, and the equals method to test a non-null reference for its value. Note that if you were to invoke any method, including the equals method, on a null reference, you'll get a NullPointerException.

For questions specific to JSPs, mosey on over to the JSP forum.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
rs.getString() returns a String.
Unless you want to check for null on a String you should always use equals.

Remember that the <%= ... %gt; block can only output Strings to the JSP output stream, so the result of your statement must be a String or be capable of being converted into a meaningful String using toString().

I agree. Here's the link:
subject: to use == or equals on getString ?
jQuery in Action, 3rd edition