简体   繁体   English

如何在Java中将Resultset.getString()与String进行比较?

[英]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.

相关问题 将 ResultSet.getString 值与来自文本字段的输入进行比较 - Compare ResultSet.getString value to an input from textfield Oracle ResultSet.getString(“ colname”)返回字符串“ null”而不是java null - Oracle ResultSet.getString(“colname”) returning the string “null” instead of java null Java 日期字段的 ResultSet.getString() 跳过毫秒 - Java ResultSet.getString() for Date field skips millisecond Java ResultSet.getString()的Date字段显示00:00:00.0 - Java ResultSet.getString() for Date field displaying 00:00:00.0 需要更改ResultSet.getString(Value) - 有条件 - Need to change ResultSet.getString(Value)-— conditionally 是什么导致Java程序不同地对待两个ResultSet.getString()方法? - What is causing Java program to treat the two ResultSet.getString() methods differently? ResultSet.getString(1)引发java.sql.SQLException:当前光标位置处的无效操作 - ResultSet.getString(1) throws java.sql.SQLException: Invalid operation at current cursor position JDBC ResultSet.getString ResultSet异常的开始/结束之前/之后 - JDBC ResultSet.getString Before/After Start/End of ResultSet Exception 使用ResultSet.getString()或ResultSet.getTimestamp()以获得时间戳更好吗? - Is it better to use ResultSet.getString() or ResultSet.getTimestamp() to get a timestamp? resultSet.getString(“ TABLE_CAT”)-什么是TABLE_CAT? - resultSet.getString(“TABLE_CAT”) - what is TABLE_CAT?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM