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
  • 38,729
  • 14
  • 126
  • 182
Warrio
  • 1,853
  • 4
  • 28
  • 45

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,567
  • 3
  • 26
  • 43