0

此 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 +
    ")";

在控制台上打印:

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 = 562570958)

此查询在直接在 MySQL 脚本中运行时有效,但在通过在 Eclipse 中运行的 Java 程序执行时无效。在 Eclipse 中运行时出现此异常:

 java.sql.SQLException: Column 'followerid' not found.

我已经有了表 Follower,其中包含列followerid。我该如何解决这个问题?

编辑:
UserClient 表有 2 列:用户 ID 和用户名。
Follower 表有 3 列:rowno、userid 和 followerid。

4

3 回答 3

1
select userclient.username 
from twitter_content.userclient as userclient 
where userclient.userid =
(select follower.followerid 
from twitter_content.follower as follower 
where follower.followerid = userclient.userid and follower.userid = 562570958)

这行得通吗?

于 2012-11-16T04:39:13.537 回答
0

打印该查询并复制它。然后尝试在 mysql 中运行该查询。

如果它工作正常,则验证与数据库的连接。它可能正在连接到没有带有“followerid”的“Follower”表的旧数据库

于 2012-11-16T04:39:22.780 回答
-2

看起来你用点而不是逗号

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 = 562570958)

也不确定为什么子查询 from 子句中有 twitter_content

于 2012-11-16T03:44:53.060 回答