所以我有一个数据库,其中有一个包含两列的表:rightWord 和 badWord。当错误的Word值等于Java中声明的变量时,我希望选择正确的Word值。到目前为止我有以下代码:
SELECT rightWord FROM dictionaryTable WHERE wrongWord = (?)
existingKeywords.next();
String rightWord = existsingKeywords.getString("rightWord");
这有效,当错误单词等于 Java 变量时,我能够获取 rightWord 列中的第一个值。现在,如何检查错误字列中的任何值是否与 Java 变量不匹配?我将上面的代码放在一个for循环中,并且java变量的值每次都不一样。
请帮忙。谢谢!
最佳答案
假设 existingKeywords
是您的 ResultSet
。当没有值时,next()
函数将返回 false
。
典型用法:
if (existingKeywords.next()) {
String rightWord = existingKeywords.getString("rightWord");
} else {
// no right word...
}
关于java - 检查Java中数据库表中是否存在单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4288061/