|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Comparing getString to String problem
I have some JSP code that's comparing a String value from a database and a hardcode value set in JSP...
String myName = "Terry"; tmp = r.getString("fname"); if (String.valueOf(tmp) == String.valueOf(myName)) { System.out.println("You da man!"); } else { System.out.println("-" + tmp + "- != -" + tmp2 + "-"); } This code prints: -Terry- != -Terry- It seems like they are different variable type (getString and String) and aren't being compared properly. I was wondering if there was some way to convert getString to be compatiable with String. Thanks for help, Terry |
|
#2
|
|||
|
|||
|
I'm gonna answer my own question...
You can't compare Strings with "==" you have to use ".equals()" ex. String tmp = "Terry" if (rs.getString("FName").equals("Terry")){ } |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Comparing getString to String problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|