【问题标题】:Check if word exists in within a database table in Java检查Java中的数据库表中是否存在单词
【发布时间】:2010-11-26 19:28:13
【问题描述】:

所以我有一个数据库,其中有一个包含两列的表:rightWord 和 wrongWord。当 wrongWord 值等于 Java 中声明的变量时,我希望选择 rightWord 值。到目前为止,我有以下代码:

SELECT rightWord FROM dictionaryTable WHERE wrongWord = (?)

existingKeywords.next();
String rightWord = existsingKeywords.getString("rightWord");

这行得通,当 wrongWord 等于 Java 变量时,我能够获得 rightWord 列中的第一个值。现在,如何检查 wrongWord 列中的任何值是否与 Java 变量不匹配?上面的代码我在for循环中,java变量的值每次都不一样。

请帮忙。谢谢!

【问题讨论】:

    标签: java database derby


    【解决方案1】:

    假设existingKeywords 是您的ResultSetnext() 函数将在没有值时返回 false

    典型用法:

     if (existingKeywords.next()) {
        String rightWord = existingKeywords.getString("rightWord");
     } else {
        // no right word...
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-24
      • 2016-06-13
      相关资源
      最近更新 更多