SQL查询在MySQL中有效,但在Eclipse中无效

时间:2012-11-16 03:36:31

标签: java mysql eclipse

此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   twitter_content.follower,其中follower.followerid = userclient.userid   和follower.userid = 562570958)

此查询在MySQL脚本中直接运行时有效,但在通过Eclipse中运行的Java程序执行时则无效。在Eclipse中运行时,我遇到了这个异常:

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

我已经拥有表格追随者,其中包含followerid列。我该如何解决这个问题?

编辑:
UserClient表有2列:userid和username 跟随者表有3列:rowno,userid和followerid。

3 个答案:

答案 0 :(得分: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)

这有用吗?

答案 1 :(得分:0)

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

如果工作正常,则验证与数据库的连接。它可能连接到没有'follower'表和'followerid'的旧数据库

答案 2 :(得分:-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)

也不确定为什么在子句中使用了子句

中的twitter_content