0

I'm trying to compare a value from a cell in a JTable and a value returned from an SQL ResultSet, but it always return FALSE even if I know they are equal.

Their content equals "1" I also checked for the length of each string which is 1.

    boolean test = (myJTable.getValueAt(0, 0).toString() == rs.getString("ID"))
    //test equals to false.

What makes them different??

Thank you in advance for your help.

Jason C
  • 35,986
  • 14
  • 111
  • 162
Warrio
  • 1,703
  • 4
  • 24
  • 44

1 Answers1

0

Don't compare String using ==, use equals() method.

Try this:

boolean test = (myJTable.getValueAt(0, 0).toString().equals(rs.getString("ID")));

For more details check this

Community
  • 1
  • 1
Salah
  • 8,304
  • 3
  • 24
  • 41