#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    12
    Rep Power
    0

    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

    Comments on this post

    • Gran Roguismo agrees
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    12
    Rep Power
    0
    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")){

    }

IMN logo majestic logo threadwatch logo seochat tools logo