在 SQL 查询中使用 Java 中声明的变量
k所以我使用Java中的Apache Derby创建了一个名为dictionaryDatabase的数据库。该数据库有一个名为dictionaryTable 的表,包含两列:wrongWord 和rightWord。 这是我到目前为止所得到的:
String keyWord = "test";
getWords = conn.prepareStatement(
"SELECT wrongWord FROM dictionaryTable WHERE wrongWord = (?)");
现在,对于每个与关键字匹配的错误单词,我希望从错误单词值与关键字匹配的同一行中的正确单词列中检索值。
我已尝试以下操作,但这不起作用:
ResultSet existingKeywords = getWords.executeQuery();
while (existingKeywords.next()) {
//Get rightWord column values here
}
我应该在这里做什么,我是否走在正确的轨道上?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你基本上从这个SQL返回
wrongWord
:为什么不创建一个类似的SQL
并且在
while
循环上,执行显然,我正在吮吸拇指,因为我不知道什么
dictionaryTable
包含列,因此这是一个假设。另外,我还没有展示如何管理 JDBC 连接。
You are basically returning
wrongWord
from this SQL:Why not create a SQL like
And on the
while
loop, doClearly, 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.