0

k so I have created a database called dictionaryDatabase using Apache Derby in Java. The database has a table called dictionaryTable and contains two columns, wrongWord and rightWord. Here's what I have so far:

String keyWord = "test";

getWords = conn.prepareStatement(
        "SELECT wrongWord FROM dictionaryTable WHERE wrongWord = (?)");

Now, for every wrongWord that does match keyWord, I wish to retrieve the value from the rightWord column in the same row in which the wrongWord value matched keyWord.

I have tried the following, but that doesn't work:

ResultSet existingKeywords = getWords.executeQuery();

while (existingKeywords.next()) {
 //Get rightWord column values here
}

What should I be doing here, and am I on the right track?

Thanks!

1 Answer 1

4

You are basically returning wrongWord from this SQL:

SELECT wrongWord FROM dictionaryTable WHERE wrongWord = (?)

Why not create a SQL like

SELECT rightWord FROM dictionaryTable WHERE wrongWord = (?)

And on the while loop, do

while (existingKeywords.next()) {
 //Get rightWord column values here
    String rightWord = existsingKeywords.getString("rightWord");
}

Clearly, I'm sucking thumb since I don't know what columns dictionaryTable contains so it's an assumption.

Also, I've not shown how manage JDBC connections.

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.