【发布时间】:2012-11-16 03:36:30
【问题描述】:
这个 SQL 查询:
String query =
"select userclient.username from twitter_content.userclient " +
"where userclient.userid = " +
"(select follower.followerid from twitter_content.follower where " +
"follower.followerid = userclient.userid and follower.userid = " +
userID +
")";
在控制台上打印:
从 twitter_content.userclient 中选择 userclient.username,其中 userclient.userid = (选择follower.followerid from twitter_content.follower where follower.followerid = userclient.userid 和follower.userid = 562570958)
此查询在直接在 MySQL 脚本中运行时有效,但在通过在 Eclipse 中运行的 Java 程序执行时无效。在 Eclipse 中运行时出现此异常:
java.sql.SQLException: Column 'followerid' not found.
我已经有了表 Follower,其中包含 followerid 列。我该如何解决这个问题?
编辑:
UserClient 表有 2 列:用户 ID 和用户名。
Follower 表有 3 列:rowno、userid 和 followerid。
【问题讨论】:
-
不熟悉 eclipse 但你需要确保它支持子查询才能在那里工作我知道 mysql 确实支持它
-
两张表都有哪些列?
-
请将两个表的 DDL 添加到您的问题中。另外,你为什么不使用 JOIN 而不是那个子选择?
-
我在上面编辑过的帖子中描述了表格。
-
你确定你真的在 mysql 和 Eclipse 中使用相同的数据库吗?