[英]How to compare Resultset.getString() to String in Java?
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. 当我打印出
resultset.getString("name")
我得到了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, 我也有一个使用
resultset.getInt("Age")
的比较器,它可以工作,所以我想也许我会聪明一点,并使用compareTo而不是equeals ,但是当我尝试时,
if(resultset.getString("name").comparesTo("George"))
I was expecting to get 0, but I get 93??? 我原本希望得到0,但是我得到93 ???
What am I missing? 我想念什么?
If .equals
does not show them to be equal, then there is a difference. 如果
.equals
不显示它们相等,则存在差异。 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. 另外,作为虚拟检查,请确保
getString
实际上返回的是String类型。 If this is a method you've defined, it could be returning something strange. 如果这是您定义的方法,则可能返回奇怪的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.