开发者

Check if word exists in within a database table in Java

开发者 https://www.devze.com 2023-01-27 16:25 出处:网络
So I have a database, within which there is a table with two columns: rightWord and wrongWord. I wish to select the rightWord value when the wrongWord value is equal to a variable declared in Java. I

So I have a database, within which there is a table with two columns: rightWord and wrongWord. I wish to select the rightWord value when the wrongWord value is equal to a variable declared in Java. I have the following code so far:

SELECT rightWord FROM dictionaryTable WHERE wrongWord = (?)

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

That works and I am able to get the first value in rightWord column when wrongWord equals the Java variable. Now, how can I check if the any of the values in the wrongWord column does not match the Java variab开发者_Python百科le? I have the above code in a for loop, and the value of the java variable is different every time.

Please help. Thanks!


Assuming existingKeywords is your ResultSet. The next() function will return false when there is no value.

Typical usage:

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

精彩评论

暂无评论...
验证码 换一张
取 消