0

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 variable? I have the above code in a for loop, and the value of the java variable is different every time.

Please help. Thanks!

1 Answer 1

1

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...
 }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.