Question

I'm trying to compare a resultset to a string, but can't seem to get it to work. This is is what I'm trying:

if(resultset.getString("name").equals("George"))

When I printout resultset.getString("name") I get George. So they should be equal?

I also have a comparator using resultset.getInt("Age") that works, so I thought maybe I could be clever and use compareTo instead of equeals, but when I try,

if(resultset.getString("name").comparesTo("George"))

I was expecting to get 0, but I get 93???

What am I missing?

Was it helpful?

Solution

If .equals does not show them to be equal, then there is a difference. Could there be a space after one of them, or perhaps some other extra character?

Try printing both of them surrounded by a known character, maybe something like:

System.out.println("*" + resultset.getString("name") + "*");

Also, as a dummy check, make sure getString is actually returning type String. If this is a method you've defined, it could be returning something strange.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top